0

サーブレットとjspで1つの小さな要件を実行しています。

サーブレットには、変数id、name、email、genderが含まれます。値がnullになる場合があります。

変数の値がnullになる場合があります。たとえば、idとnameには、値1123とpratapが含まれています。

response.setContentType("text/html;charset=UTF-8");
              try {
             //TODO output your page here
        RequestDispatcher view = request.getRequestDispatcher("registration.jsp");
    view.forward(request, response);
           request.setAttribute("id","value"); 
        } finally {            

        }

私のjspページ

 <%@page contentType="text/html" pageEncoding="UTF-8"%>
    <!DOCTYPE html>
    <html>
        <head>
            <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
            <title>JSP Page</title>
        </head>
        <body>
          <form method="GET" action='registration1'>
    <input type="text" name="address"/>
    <input type="text" name="phoneno"/>

    <input type="text" name="pincode" />
    <label>${id}</label>
    <input type="submit"/>
    </form>
        </body>
    </html>

コントロールがregistration.jspに移動するようにします

register.jspで、電子メールと性別のテキストボックスを取得し、IDと名前のテキストボックスで、ユーザーがこれらの値を変更できないようにする必要があります(これらの値はすでに入力されており、正しいことが証明されているため) 。)

上記のjspの場合、idで試しましたが、jspでid値を確認できません。

これらの変数をjspのテキストボックスに渡す方法と、値がnullの場合に値を入力するように求めるプロンプトを表示する方法。

ありがとうございました..

4

1 に答える 1

1

サーブレットでリクエスト属性として値を設定し、JSPで取得する必要があります。それらをJSPで取得した後、それに応じてチェックし、フォームコントロールを有効/無効にします。

サーブレット:

request.setAttribute("phoneno","9998386033");

JSP:

<%
String phoneno=null;
if(request.getAttribute("phoneno")!=null) 
    phoneno = request.getAttribute("phoneno").toString();
%>

<% if(phoneno!=null) {
     out.println("<INPUT TYPE=\"text\" name=\"phoneno\" value=\""+phoneno+"\" disabled=\"disabled\" ");
   } else {
       out.println("<INPUT TYPE=\"text\" name=\"phoneno\" ");
   }
%>

JSPELの場合

<c:if test="${empty phoneno}">
    <INPUT TYPE="text" name="phoneno" value="${phoneno}" disabled="disabled"/>
</c:if>
<c:if test="${not empty phoneno}">
    <INPUT TYPE="text" name="phoneno"/>
</c:if>
于 2012-05-14T12:16:27.450 に答える