Can we redirect one jsp page to another jsp page
Asked Answered
A

6

5

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?

Abampere answered 7/5, 2014 at 12:31 Comment(5)
response.sendRedirect() should doSikorski
Using Javascript, without submitting the form: window.location = "theNewUrl.jsp".Veneer
is there some other way other than window.location? I have to it through form.Abampere
So you want to submit the form, then send back a redirect in the response? If so, there's an answer for that already...Veneer
@Brain : <jsp:forward page="relativeURL" />Use this action tag to forward the request to another resource it may be a JSP.Hakon
K
2

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();
}
Kim answered 7/5, 2014 at 12:51 Comment(0)
L
8

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");
%>
Luff answered 7/5, 2014 at 12:40 Comment(0)
O
5

You can also try this

<jsp:forward page = "abc.jsp" />
Oeuvre answered 7/4, 2015 at 22:36 Comment(0)
T
3

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"/>
Tarrance answered 7/5, 2014 at 12:38 Comment(2)
I have to do it through form friend :)Abampere
write the code in java script function as follows window.location.href = "/xxx.jsp";Tarrance
K
2

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();
}
Kim answered 7/5, 2014 at 12:51 Comment(0)
M
1

You can also call page directly with:

<jsp:redirect page="xyz.jsp" />
Marquisette answered 7/5, 2014 at 12:42 Comment(0)
S
0
use the following code to redirect on another page in js...

$('#abc_id').click(function() {
            updateSubContent("abc.jsp");
        });
Stoeber answered 23/11, 2017 at 10:38 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.