File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to redirect to a new page using JSP?

 
Reeth Suresh A
Greenhorn
Posts: 5
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I will be generating a URL String in my java code.
1) I want this code to be accessed by a JSP
2) The JSP should redirect to a new page( new page is this URL from java code)

How should I write my JSP for this?

Thanks & Regards,
Reeth
 
Seetharaman Venkatasamy
Ranch Hand
Posts: 5575
Eclipse IDE Java Windows XP
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Reeth Suresh A wrote:
I will be generating a URL String in my java code.
2) The JSP should redirect to a new page( new page is this URL from java code)


Use servlet to redirect . are you using servlet in your module?
 
Reeth Suresh A
Greenhorn
Posts: 5
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No I am not using any servlet here. I am working on Documentum. This is just a simple java class. The URL string generated in the java class has to be used by the JSP to redirect
 
samir singha
Greenhorn
Posts: 23
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can use jsp implicit object response's sendRedirect method. It will look like response.sendRedirect("url") or can use servlet's RequestDispatcher. Hope this will help
 
Seetharaman Venkatasamy
Ranch Hand
Posts: 5575
Eclipse IDE Java Windows XP
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
samir singha wrote:can use servlet's RequestDispatcher. Hope this will help


Nop. you cant. sendRedirect is completely different . it makes new request,response object [client side]
 
Reeth Suresh A
Greenhorn
Posts: 5
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is this possible

window.location="URl"..

But this URl is generated in my java code..how do I get this here?
 
Seetharaman Venkatasamy
Ranch Hand
Posts: 5575
Eclipse IDE Java Windows XP
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Reeth Suresh A wrote:
window.location="URl"..


it is javascript
 
Reeth Suresh A
Greenhorn
Posts: 5
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
yeah its a java script...
 
Seetharaman Venkatasamy
Ranch Hand
Posts: 5575
Eclipse IDE Java Windows XP
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Reeth Suresh A wrote:yeah its a java script...


then you need to pass the url value from jsp to javascript function
 
Reeth Suresh A
Greenhorn
Posts: 5
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
eg:
THis is my java class:
Class A
{
method 1()
{
String url="....";
}
}

This is my JSP:
<%@ page import="A(my class)" %>
<head>
<script type="text/javascript">
window.location=request.getParameter(url);
</script>

Is this correct?
</head>
 
Seetharaman Venkatasamy
Ranch Hand
Posts: 5575
Eclipse IDE Java Windows XP
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
1.jsFunction('${url}')//preferred way

2.jsFunction('<%= request.getParameter("url") %>')



 
Eduardo Bueno
Ranch Hand
Posts: 155
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That will not work. If you want to pass a parameter from a java class to a JSP you must use a Servlet, otherwise you can use scriptlets inside your JSP (it is an option but don't do this).
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic