This week's book giveaway is in the OCMJEA forum.
We're giving away four copies of OCM Java EE 6 Enterprise Architect Exam Guide and have Paul Allen & Joseph Bambara on-line!
See this thread for details.
The moose likes Servlets and the fly likes how to redirect servlet to jsp on weblogic Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "how to redirect servlet to jsp on weblogic" Watch "how to redirect servlet to jsp on weblogic" New topic
Author

how to redirect servlet to jsp on weblogic

prashant wath
Greenhorn

Joined: Oct 19, 2001
Posts: 9
hi,
I am trying to redirect from servlet to jsp on weblogic server through HttpResponse object res.sendRedirect(urlString).Servlet is executing well also weblogic didn't show any message,but the response didn't redirect to destination jsp page.
What's the problem can anybody give me a solution.Shall i use responseDispatcher.if so what's the diff between sendRedirect & requestDispatcher.
pls help at the earliest.
sowmya vasisht
Ranch Hand

Joined: Aug 23, 2001
Posts: 35
hello
the res.sendRedirect will redirect to the jsp the only thing you have to check whether you have given correct path of the jsp where you have created. i think that is the only place you would have gone wrong. otherwise the sendRedirect will work. check out the path of the jsp you have given in the res.sendRedirect("---");
regds
sowmya
Saravanan V
Greenhorn

Joined: Sep 20, 2001
Posts: 15
Hi Prashant
Response.sendRedirect() should work fine.There can be no probs with that.Just check u have given the jsp path correctly.If u have put it in public_html then u should call as Response.sendRedirect("/filename.jsp").This will work fine.
RequestDispatcher will forward the request to servlet or jsp page.
prashant wath
Greenhorn

Joined: Oct 19, 2001
Posts: 9
hi sowmya,
Thanks for the reply.I checked the path it's correct.But my jsp & servlet pages are in diff directories.
jsp are in c:/weblogic/myserver/public_html/admin directory
servlet are in c:/weblogic/myserver/servletclasses directory,
my url in sendRedirect is http://localhost:7001/admin/home.html.
If i am writting same url on browser the page home.html opens.
Can there be someother problem.Pls advise
prashant wath
Greenhorn

Joined: Oct 19, 2001
Posts: 9
hi sowmya,
Can u pls advise me on this problem
i had 3 pages
home.html
a.jsp
b.jsp
if user requests for b.jsp from home.html then it should be opened in the same window.
Otherwise if user requests for b.jsp from a.jsp then it should open in the different window.
is it possible by javascript or someother means.
thanks
Gowrishankar Mudaliar
Ranch Hand

Joined: Oct 20, 2001
Posts: 39
Prashanth,
I think, the best option is to use javax.servlet.RequestDispatcher.forward();
This is the very common way to forward data from a servlet to any other resource like JSP, php etc.
First you should get the RequestDispatcher reference for that particular jsp, by
RequestDispatcher dispatcher = getServletContext().getRequestDispatcher("/path/abc.jsp");
Then,
dispatcher.forward(request,response);
Hope you can use this
Gowri Shankar
sowmya vasisht
Ranch Hand

Joined: Aug 23, 2001
Posts: 35
hello prashanth
there is a method in javascript to open a jsp page in a new window you can do that by using a method called window.open("URL of the jsp"); this function can be called onclick of some button or the from the widget you wish to open the jsp in a new window
that will solve the problem.
in the send redirect the path should be given
as admin/xyz.jsp this should be working fine.
regds sowmya
Saravanan V
Greenhorn

Joined: Sep 20, 2001
Posts: 15
Prashant
Hope this is what ur settings are..
document root is public_html/admin where u place all jsp and html pages.u can access the html and jsp pages by this url.
"http://localhost:7001/file.html"
try to give response.sendRedirect("/file.jsp"); in ur servlet.hope this helps..
Kyle Brown
author
Ranch Hand

Joined: Aug 10, 2001
Posts: 3892
    
    5
I've noticed that no one has addressed your question yet on what the difference is between using HttpResponse.sendRedirect() and using RequestDispatcher.forward().
The sendRedirect() method basically sends back a special HTTP code to the browser that indicates that the browser should request the page that is sent as the argument to the method. This requires one additional client-server round-trip. Basically, it looks like the following
Browser --> Servlet service() method
<-- (send redirect to "page")
Browser --> HTTP GET ("page")
<-- (return "page" to Browser)
When you use a RequestDispatcher.forward() what happens is that the page is invoked (which for a servlet or JSP invokes the service() method) on the server without having to go back to the browser a second time. It looks like the following:
Browser --> Servlet (forward to JSP page)
JSP page generates output (service() method)
<-- (output of JSP returned to Browser)
As you can imagine, it's sometimes significantly faster to do a Requestdispatcher.forward() than a sendRedirect() since you skip the extra round trip. However, that's not the real reason to do so. When a Servlet or JSP does a RequestDispatcher.forward() to another Servlet or JSP, the HttpRequest object passed to the second servlet or JSP is the SAME one that was first passed to the original one. This means that the Servlet could (for instance) write attributes to the HttpRequest object that the JSP could use to produce output.
This behavior is key to the "Model II" or "MVC" architecture for servlets described in my book, or the J2EE design patterns.
Good luck with your problem.
Kyle
------------------
Kyle Brown,
Author of Enterprise Java (tm) Programming with IBM Websphere
See my homepage at http://members.aol.com/kgb1001001 for other WebSphere information.


Kyle Brown, Author of Persistence in the Enterprise and Enterprise Java Programming with IBM Websphere, 2nd Edition
See my homepage at http://www.kyle-brown.com/ for other WebSphere information.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: how to redirect servlet to jsp on weblogic