Redirecting to Another Page With JavaScript and Jsp

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



Leave a reply



Submit