aspose file tools*
The moose likes Servlets and the fly likes Servlet chaining Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "Servlet chaining " Watch "Servlet chaining " New topic
Author

Servlet chaining

Praveen K Pippiri
Greenhorn

Joined: Jun 17, 2002
Posts: 23
Hi All,
I am facing problem in forwarding the request to a jsp.I know that this issue is being discussed several times but the solution is not working out.
I am using Visual Age for Java Professional Edition which is an Java editor and provides IBM websphere 3.5 test environment.
I am using the folloing code to forward it to jsp.
public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
{
performTask(request, response);
}
public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
{
performTask(request, response);
}

public void performTask(HttpServletRequest request, HttpServletResponse response)
{
//some processing
ServletContext sc = getServletContext();
RequestDispatcher rd = sc.getRequestDispatcher("/Test.jsp");
rd.forward(request, response);
System.out.println("In the end");
}
It is displaying "Page can not be displayed Interneal server error 500"
Strange thing is that it is actually reading the jsp file and executing the scriptlet of the jsp.(i.e,page is accessible )
And it is executing the system.out.println code in the servlet after forward.As far as My understanding,it should forward the request immediately after the forward method.
Could you please help me out??
Thanks in Advance
Pravs
Juanjo Bazan
Ranch Hand

Joined: Feb 04, 2002
Posts: 231
You can try the sendRedirect method.
[ July 18, 2002: Message edited by: Juanjo Bazan ]
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12803
    
    5
Have you looked at the logs to see if an exception is being reported? Consider putting your calls to performTask inside a try{}catch(){} structure and have any exception print a complete stack trace. Does your JSP page designate an errorPage?
Bill
Wayne Turner
Greenhorn

Joined: Jul 18, 2002
Posts: 12
Sorry about the previous posting. I am new here, and obviously made a mistake.
I think your problem is that you need an absolute path to the resource, since you are using the Web Dispatcher. See:
http://java.sun.com/webservices/docs/ea1/tutorial/doc/Servlets9.html
Frank Carver
Sheriff

Joined: Jan 07, 1999
Posts: 6920
That's OK. I have deleted it for you now. For the future, if you accidentally do something like that again, note that you can delete your own posts.
Just click on the "pen and paper" icon above the post (normally used to edit posts), select the "delete this post" checkbox, and press the button. Your accidental post will be gone!


Read about me at frankcarver.me ~ Raspberry Alpha Omega ~ Frank's Punchbarrel Blog
Wayne Turner
Greenhorn

Joined: Jul 18, 2002
Posts: 12
Thanks Frank...
Now, I've been trying to do an 'include' on this RequestDispatch.. Kinda tricky. What I said before is correct, but at first I had a hard time getting my server to create a RequestDispatcher. I ended up creating one from the request object. Next, I had to be sure NOT to include a "/" in front of my servlet name, it really is a relative reference. Don't know why I couldn't get the RequestDispatch object from the servlet context.
But most interestlying enough, while I found I MUST create a PrintWriter object in the called servlet, I SHOULD NOT CLOSE IT AT THE END OF THE CALLED SERVLET'S doGet method. If I did, nothing else would print after that in the original calling servlet.
OH YES...This too. Be sure to put something like this in your target include servlet......
public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
{
doGet(request, response);
}

}
I typically put everything in the doGet method. It looks like the include method calls the doPost method of the target servlet.
Finally got the stuff to work. Good luck!
Praveen K Pippiri
Greenhorn

Joined: Jun 17, 2002
Posts: 23
Thanks all for helping me out.
I found out the problem.Partially the problem is due to the visual age for Java itself(I guess so)After several attempts,the message changed to "Target Servlet: null" and IllegalStateException .That is b'coz I instaintiated PrintWriter object and didn't close it.
 
Don't get me started about those stupid light bulbs.
 
subject: Servlet chaining