Close button in jsp page not working after response is redirected from servlet to jsp












1















I have a Submit button on my jsp(Welcome.jsp) page upon which I send the request to myservlet(Import Parts). I do some validation in servlet and upon failing on the validation I redirect user to the error.jsp page which give a suitable message. This error.jsp also has a close button which does not work after I forward the response to error.jsp.



If I directly launch the error.jsp in browser and try to click the close button, it works.



// 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.









share|improve this question























  • try getting rid of the if in your servlet to see the behaviour. what kind of message dou you get?

    – Jose
    Dec 28 '18 at 20:09











  • If statement is not causing a problem here because the behavior remains same. In case I remove if, I will be redirected to my error.jsp page on which the close button still don't work. However if I directly run the error.jsp page and try to click on close button, it closes the browser window but the same button does not work when I forward from my servlet to this error.jsp.

    – Tapan
    Dec 29 '18 at 7:52













  • This is still unanswered, any help will be appreciated.

    – Tapan
    Dec 30 '18 at 18:29
















1















I have a Submit button on my jsp(Welcome.jsp) page upon which I send the request to myservlet(Import Parts). I do some validation in servlet and upon failing on the validation I redirect user to the error.jsp page which give a suitable message. This error.jsp also has a close button which does not work after I forward the response to error.jsp.



If I directly launch the error.jsp in browser and try to click the close button, it works.



// 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.









share|improve this question























  • try getting rid of the if in your servlet to see the behaviour. what kind of message dou you get?

    – Jose
    Dec 28 '18 at 20:09











  • If statement is not causing a problem here because the behavior remains same. In case I remove if, I will be redirected to my error.jsp page on which the close button still don't work. However if I directly run the error.jsp page and try to click on close button, it closes the browser window but the same button does not work when I forward from my servlet to this error.jsp.

    – Tapan
    Dec 29 '18 at 7:52













  • This is still unanswered, any help will be appreciated.

    – Tapan
    Dec 30 '18 at 18:29














1












1








1








I have a Submit button on my jsp(Welcome.jsp) page upon which I send the request to myservlet(Import Parts). I do some validation in servlet and upon failing on the validation I redirect user to the error.jsp page which give a suitable message. This error.jsp also has a close button which does not work after I forward the response to error.jsp.



If I directly launch the error.jsp in browser and try to click the close button, it works.



// 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.









share|improve this question














I have a Submit button on my jsp(Welcome.jsp) page upon which I send the request to myservlet(Import Parts). I do some validation in servlet and upon failing on the validation I redirect user to the error.jsp page which give a suitable message. This error.jsp also has a close button which does not work after I forward the response to error.jsp.



If I directly launch the error.jsp in browser and try to click the close button, it works.



// 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.






java jsp servlets






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Dec 28 '18 at 19:39









TapanTapan

62




62













  • try getting rid of the if in your servlet to see the behaviour. what kind of message dou you get?

    – Jose
    Dec 28 '18 at 20:09











  • If statement is not causing a problem here because the behavior remains same. In case I remove if, I will be redirected to my error.jsp page on which the close button still don't work. However if I directly run the error.jsp page and try to click on close button, it closes the browser window but the same button does not work when I forward from my servlet to this error.jsp.

    – Tapan
    Dec 29 '18 at 7:52













  • This is still unanswered, any help will be appreciated.

    – Tapan
    Dec 30 '18 at 18:29



















  • try getting rid of the if in your servlet to see the behaviour. what kind of message dou you get?

    – Jose
    Dec 28 '18 at 20:09











  • If statement is not causing a problem here because the behavior remains same. In case I remove if, I will be redirected to my error.jsp page on which the close button still don't work. However if I directly run the error.jsp page and try to click on close button, it closes the browser window but the same button does not work when I forward from my servlet to this error.jsp.

    – Tapan
    Dec 29 '18 at 7:52













  • This is still unanswered, any help will be appreciated.

    – Tapan
    Dec 30 '18 at 18:29

















try getting rid of the if in your servlet to see the behaviour. what kind of message dou you get?

– Jose
Dec 28 '18 at 20:09





try getting rid of the if in your servlet to see the behaviour. what kind of message dou you get?

– Jose
Dec 28 '18 at 20:09













If statement is not causing a problem here because the behavior remains same. In case I remove if, I will be redirected to my error.jsp page on which the close button still don't work. However if I directly run the error.jsp page and try to click on close button, it closes the browser window but the same button does not work when I forward from my servlet to this error.jsp.

– Tapan
Dec 29 '18 at 7:52







If statement is not causing a problem here because the behavior remains same. In case I remove if, I will be redirected to my error.jsp page on which the close button still don't work. However if I directly run the error.jsp page and try to click on close button, it closes the browser window but the same button does not work when I forward from my servlet to this error.jsp.

– Tapan
Dec 29 '18 at 7:52















This is still unanswered, any help will be appreciated.

– Tapan
Dec 30 '18 at 18:29





This is still unanswered, any help will be appreciated.

– Tapan
Dec 30 '18 at 18:29












1 Answer
1






active

oldest

votes


















0














In a form, to submit the details, the input type should be submit but not button. Change your code this way. It should work :)



<form>
<td align="center"><input type="submit" value="Close" onclick="window.close();" /></td>
</form>





share|improve this answer


























  • The flow of the code is -- Welcome.jsp - > User clicks Submit button on welcome.jsp and the request goes to Servlet. -> I call a method from servlet which returns true/false-> On false I redirect user to error.jsp page which contains close button. I do not understand why I need submit button in error.jsp, since I am not sending any request from error.jsp page.

    – Tapan
    Dec 29 '18 at 7:35













Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53963540%2fclose-button-in-jsp-page-not-working-after-response-is-redirected-from-servlet-t%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









0














In a form, to submit the details, the input type should be submit but not button. Change your code this way. It should work :)



<form>
<td align="center"><input type="submit" value="Close" onclick="window.close();" /></td>
</form>





share|improve this answer


























  • The flow of the code is -- Welcome.jsp - > User clicks Submit button on welcome.jsp and the request goes to Servlet. -> I call a method from servlet which returns true/false-> On false I redirect user to error.jsp page which contains close button. I do not understand why I need submit button in error.jsp, since I am not sending any request from error.jsp page.

    – Tapan
    Dec 29 '18 at 7:35


















0














In a form, to submit the details, the input type should be submit but not button. Change your code this way. It should work :)



<form>
<td align="center"><input type="submit" value="Close" onclick="window.close();" /></td>
</form>





share|improve this answer


























  • The flow of the code is -- Welcome.jsp - > User clicks Submit button on welcome.jsp and the request goes to Servlet. -> I call a method from servlet which returns true/false-> On false I redirect user to error.jsp page which contains close button. I do not understand why I need submit button in error.jsp, since I am not sending any request from error.jsp page.

    – Tapan
    Dec 29 '18 at 7:35
















0












0








0







In a form, to submit the details, the input type should be submit but not button. Change your code this way. It should work :)



<form>
<td align="center"><input type="submit" value="Close" onclick="window.close();" /></td>
</form>





share|improve this answer















In a form, to submit the details, the input type should be submit but not button. Change your code this way. It should work :)



<form>
<td align="center"><input type="submit" value="Close" onclick="window.close();" /></td>
</form>






share|improve this answer














share|improve this answer



share|improve this answer








edited Dec 29 '18 at 7:09









lucumt

5,61221022




5,61221022










answered Dec 28 '18 at 20:15









PavanPavan

7101038




7101038













  • The flow of the code is -- Welcome.jsp - > User clicks Submit button on welcome.jsp and the request goes to Servlet. -> I call a method from servlet which returns true/false-> On false I redirect user to error.jsp page which contains close button. I do not understand why I need submit button in error.jsp, since I am not sending any request from error.jsp page.

    – Tapan
    Dec 29 '18 at 7:35





















  • The flow of the code is -- Welcome.jsp - > User clicks Submit button on welcome.jsp and the request goes to Servlet. -> I call a method from servlet which returns true/false-> On false I redirect user to error.jsp page which contains close button. I do not understand why I need submit button in error.jsp, since I am not sending any request from error.jsp page.

    – Tapan
    Dec 29 '18 at 7:35



















The flow of the code is -- Welcome.jsp - > User clicks Submit button on welcome.jsp and the request goes to Servlet. -> I call a method from servlet which returns true/false-> On false I redirect user to error.jsp page which contains close button. I do not understand why I need submit button in error.jsp, since I am not sending any request from error.jsp page.

– Tapan
Dec 29 '18 at 7:35







The flow of the code is -- Welcome.jsp - > User clicks Submit button on welcome.jsp and the request goes to Servlet. -> I call a method from servlet which returns true/false-> On false I redirect user to error.jsp page which contains close button. I do not understand why I need submit button in error.jsp, since I am not sending any request from error.jsp page.

– Tapan
Dec 29 '18 at 7:35




















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53963540%2fclose-button-in-jsp-page-not-working-after-response-is-redirected-from-servlet-t%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Angular Downloading a file using contenturl with Basic Authentication

Olmecas

Can't read property showImagePicker of undefined in react native iOS