• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Paul Clapham
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Roland Mueller
  • Piet Souris
Bartenders:

How to redirect to a new page using JSP?

 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 5575
Eclipse IDE Windows XP Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 Windows XP Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 Windows XP Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Reeth Suresh A wrote:
window.location="URl"..



it is javascript
 
Reeth Suresh A
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
yeah its a java script...
 
Seetharaman Venkatasamy
Ranch Hand
Posts: 5575
Eclipse IDE Windows XP Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 Windows XP Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
1.jsFunction('${url}')//preferred way

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



 
Ranch Hand
Posts: 159
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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).
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic