aspose file tools*
The moose likes Sockets and Internet Protocols and the fly likes Call servlet from java class and redirect to jsp page Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Sockets and Internet Protocols
Bookmark "Call servlet from java class and redirect to jsp page" Watch "Call servlet from java class and redirect to jsp page" New topic
Author

Call servlet from java class and redirect to jsp page

limitha adulla
Greenhorn

Joined: Jul 27, 2009
Posts: 4
Hi all

I am very new to this site.

just want to call servelt from java class where servelt redirectd to jsp page.

I have tried to call servlet from java class using following code

URL url = new URL("http://localhost:9090/servlet");

URLConnection conn = url.openConnection();

BufferedReader in = new BufferedReader(new InputStreamReader(conn.getInputStream()));

but i am redirecting servlet to jsp page which i can't do it. Can please suggest me how to do it.
carina caoor
Ranch Hand

Joined: Jun 23, 2007
Posts: 300

To dispatch a request from servlet to JSP you can use RequestDispatcher.
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41532
    
  53
RequestDispatcher does a server-side forward, not a client-side redirect.

You can cast the URLConnection object to an HttpURLConnection, and then use the "setFollowRedirects(true)" method.


Ping & DNS - my free Android networking tools app
limitha adulla
Greenhorn

Joined: Jul 27, 2009
Posts: 4
hi Ulf Dittmer

Can please send me detailed code where to use setFollowRedirects(true) method i have tried but it doesn't work.
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41532
    
  53
What have you tried, and what happened? Post the code.
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18541
    
    8

I believe that following redirects is the default behaviour for HttpURLConnection, isn't it? So the problem may be that the servlet isn't designed to redirect to the JSP. If that's the case then your client-side component (the URLConnection) can't affect how the server side is designed to work. But you could follow up by sending a second request to the JSP.

That's speculation, though. We don't know how things are supposed to work on the server, we don't know what you are doing on the client, and we don't know what is happening that shouldn't be happening. Or vice versa.
limitha adulla
Greenhorn

Joined: Jul 27, 2009
Posts: 4
hi Ulf Dittmer

can please tell me how to use setFollowRedirects(true) method.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Call servlet from java class and redirect to jsp page