我在jsp页面中有一个html表单,它在提交时将执行servlet中的函数,我再次将它重定向到调用它的同一个jsp页面,并使用一条成功消息显示在同一个jsp页面上,但我不知道如何做到这一点.
这是我的jsp表单代码。
<form action="CallTimer" method="GET">
<label class="button2">Set Date: </label>
<input type="text" name="date" id="date">
<label class="button2">Set Hour </label>
<input type="text" name="hour" id="hour">
<label class="button2">Set Minute: </label>
<input type="text" name="minute" id="minute">
<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>
这里是我的servlet重定向代码。
response.sendRedirect("Automail.jsp");
发布于 2013-11-14 07:56:21
根据您的要求,我建议您选择ajax,我给出了一个简单的示例,如何将数据传递给servlet.单击此处,以了解jquery的更多信息
$.ajax(
{
type: "get",
url: "CallTimer", //Your full URL goes here
data: { name: name1, date: date1,hour:hour1,filepath:filepath1,minute:minute1},
success: function(data, textStatus, jqXHR){
alert("success");
},
error: function(jqXHR){
alert(jqXHR.responseStatus);
}
});
注意名称-参数名称和name1参数值、小时参数名称和hour1参数value.Similarily在窗体中使用get操作,因为参数值将显示在url中,并且限制为2048个字符。
发布于 2013-11-14 07:39:31
在Servlet上:
// You need to set value in session for redirection.
session.setAttribute("msg","Success");
response.sendRedirect("Automail.jsp");
在Automail.jsp
${msg}
发布于 2013-11-14 07:39:57
在servlet中:
response.sendRedirect("Automail.jsp?success=1");
在您的jsp中:
<c:if test="${param.success eq 1}">
<div> success </div>
</c:if>
https://stackoverflow.com/questions/19972073
复制相似问题