Pallav Raj
Pallav Raj

Reputation: 1744

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?

Upvotes: 5

Views: 90926

Answers (6)

Prashant
Prashant

Reputation: 1

use the following code to redirect on another page in js...

$('#abc_id').click(function() {
            updateSubContent("abc.jsp");
        });

Upvotes: 0

Nerys
Nerys

Reputation: 51

You can also try this

<jsp:forward page = "abc.jsp" />

Upvotes: 5

Susheel Singh
Susheel Singh

Reputation: 3854

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();
}

Upvotes: 2

Pramod S. Nikam
Pramod S. Nikam

Reputation: 4539

You can also call page directly with:

<jsp:redirect page="xyz.jsp" />

Upvotes: 1

Mustafa sabir
Mustafa sabir

Reputation: 4360

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");
%>

Upvotes: 8

Naveen
Naveen

Reputation: 535

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

Upvotes: 3

Related Questions