我在jsp(Welcome.jsp)页面上有一个Submit按钮,通过该按钮我可以将请求发送到myservlet(Import Parts)。我在servlet中进行了一些验证,验证失败后,我将用户重定向到error.jsp页面,该页面提供了适当的消息。我将响应转发到error.jsp之后,此error.jsp也具有关闭按钮,该按钮不起作用。
如果我直接在浏览器中启动error.jsp并尝试单击关闭按钮,它将起作用。
// Below is the piece of code written in my Servlet on doPost() method which perform some validation and upon failing the validation check redirects user to error.jsp page.
if(!UserDetails.checkValidUser(asession)) //a Validation method returning true or false
{
logger.info("User do not have necessary role");
request.setAttribute("error", EMSImportConstants.NO_PRIVILEGE_USER_ERR_MESSAGE);
RequestDispatcher rd = request.getRequestDispatcher("/Error.jsp");
rd.forward(request, response);
}
//Below is my error.jsp page code
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path;
%>
<html>
<head>
<title>Error in EMS BOM Import</title>
<link href="<%=basePath %>/css/netapps.css" rel="stylesheet" type="text/css" />
</head>
<body bgcolor="#ffffff" class="borderless">
<form method="post" action="Error.jsp">
<center>
<div id="banner">
<div id="logo"></div>
<div id="rightbg">
<div id="bannerTitle"><br>EMS BOM Import</div>
</div>
<div id="bannerImage"> </div>
</div>
</center>
<br />
<br />
<br />
<br />
<center>
<font size = "2px" color="red">
<%=request.getAttribute("error") %>
</font>
<table>
<tr>
<td align="center"><input type="button" value="Close" onclick="window.close();"/></td>
</tr>
</table>
</center>
</form>
</body>
</html>
I click on close button but nothing happens.
答案 0 :(得分:0)
在表单中,要提交详细信息,input
类型应为submit
,而不是button
。以此方式更改代码。它应该可以工作:)
<form>
<td align="center"><input type="submit" value="Close" onclick="window.close();" /></td>
</form>