Redirecting to another page with JavaScript and JSP
I think you could do it this way:
...
int result = adminClasses.userfunctions.addNewUser(u);
if (result == 0) {
request.getRequestDispatcher("signupSuccess.jsp").forward(request, response);
}
...
It will evaluate the result
on the server side and then, depending on the result
, will forward to a signupSuccess.jsp
page – i.e. the URL will stay the same, but the response will include success page's evaluated content.
How to redirect to another JSP page via JavaScript in MVC portlet?
Anyways had solved my problem with the following code:
function getbuttonId(sid){
alert("Are You Sure You want to Edit");
// document.editform.action=url;
// document.editform.submit();
var textbox = document.getElementById('hiddenkey');
textbox.value=sid;
document.editform.action = "<%=editURL.toString() %>";
document.editform.submit();
return false ;
}
and onclick of button I am calling the above javascript method. So it works good.
Actually what I want was the id of particular button which is clicked so I am storing that id in hidden key and after form submit action in java script I am redirecting to page I want and then I can get the value of hidden key field from the request.getattribute(hiddenkey field name).
Can we redirect one jsp page to another jsp page
Try this:
<form id="main" method="post" name="main" action="" onsubmit="redirect(this);">
<input type="submit" name="submit"/>
</form>
function redirect(elem){
elem.setAttribute("action","somepage.jsp");
elem.submit();
}
jsp page redirects to next page even when if condition of JS is true
Change your submit
button declaration to
<input type="submit" onclick="return date_compare();" value="Submit" />
JSP Page not redirecting to another JSP after confirmation on the alert box
Cookies and session are unrelated to redirects; both are persistent: one on the client (cookies), one on the server (sessions).
The correct JS would be window.location = xxx
.
A simple look at the JavaScript console would show you the JS error.
Related Topics
Calculate String Value in Javascript, Not Using Eval
How to Refresh an Angular Component
How to Make a Modal Popup to Take an Input Value Using Jquery or JavaScript
Starting the Week on Monday With Isoweekday()
Onchange Event Updates State With 1 Character Delay
How to Open a Web Page Automatically in Full Screen Mode
Reactjs Dynamic Drop Down Populated With Map Function
Detect Click into Iframe Using JavaScript
Fullcalendar - Change View for Mobile Devices
Element Implicitly Has an 'Any' Type Because Index Expression Is Not of Type 'Number' [7015]
How to Change Image When Two Buttons Are Clicked
Why Am I Not Able to Add Input Text into My Table
How to Call a Function When Element Is Loaded At Angular
Switch Fontawesome Icon on Click, Not Working
How to Wrap Each Word of an Element in a Span Tag
Ajax - How to Use a Returned Array in a Success Function
How to Call the Same Method for Different Elements With Different Ids