5

送信時にサーブレットに送信されるjspページにhtmlフォームがあります..サーブレットで関数を実行した後、同じjspに表示する成功メッセージで呼び出された同じjspページに再度リダイレクトしていますページですが、これを行う方法がわかりません...

これが私のjspフォームコードです..

 <form action="CallTimer" method="GET">
    <label class="button2">Set Date: </label>
    <input type="text" name="date" id="date">
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
    <label class="button2">Set Hour </label>
    <input type="text" name="hour" id="hour">
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
    <label class="button2">Set Minute: </label>
    <input type="text" name="minute" id="minute">
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
    <input type="Submit" name="Submit" value="Submit" id="Submit">
    <br/><br/>
    <label class="button2">Set File-Path: </label>
    <input type="text" name="filepath" id="filepath">
</form>

そして、これが私のサーブレットリダイレクトコードです。

response.sendRedirect("Automail.jsp");
4

4 に答える 4

7

サーブレットで:

 // You need to set value in session for redirection.
 session.setAttribute("msg","Success");

 response.sendRedirect("Automail.jsp");

Automail.jsp

  ${msg}
于 2013-11-14T07:39:31.113 に答える
3

サーブレット内:

response.sendRedirect("Automail.jsp?success=1");

あなたのjspで:

<c:if test="${param.success eq 1}">
     <div> success </div>
</c:if>
于 2013-11-14T07:39:57.903 に答える
1

サーブレット内:

session.setAttribute("message","successful");
response.sendRedirect("Automail.jsp");

JSP の場合:

<c:if test="${not empty message}">
    <h3 style='color:green'>${message}</h3>
    <c:remove var="message"/>
</c:if>

ページの更新後にメッセージが含まれないように、印刷後に変数を削除することを忘れないでください。

于 2019-06-18T18:53:31.753 に答える