Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can we redirect one jsp page to another jsp page

I want to open a jsp page without accessing my servlete code. i.e. I neither have to input my url in (action="url") my jsp code nor have to access my Servlete code.

<form id="main" method="post" name="main" action="dpRegPost" onsubmit="return validate();">

Can anyone help me in this?

like image 256
Pallav Raj Avatar asked May 07 '14 12:05

Pallav Raj


4 Answers

You can add javascript to your jsp file

<script type="text/javascript">
window.location.href = "www.google.com";
</script>

or using jsp

<%

    response.sendRedirect("www.google.com");
%>
like image 110
Mustafa sabir Avatar answered Oct 20 '22 21:10

Mustafa sabir


You can also try this

<jsp:forward page = "abc.jsp" />
like image 37
Nerys Avatar answered Oct 20 '22 20:10

Nerys


Use jstl taglibrary in your current jsp page.Make available the taglibrary using below code

 <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>  

Use Following code in jsp to redirect

<c:redirect url="/xxx.jsp"/>
like image 3
Naveen Avatar answered Oct 20 '22 20:10

Naveen


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();
}
like image 2
Susheel Singh Avatar answered Oct 20 '22 19:10

Susheel Singh