Win a copy of Real-World Software Development: A Project-Driven Guide to Fundamentals in Java this week in the Agile and Other Processes forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Liutauras Vilda
  • Knute Snortum
  • Bear Bibeault
Sheriffs:
  • Devaka Cooray
  • Jeanne Boyarsky
  • Junilu Lacar
Saloon Keepers:
  • Ron McLeod
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
  • salvin francis
Bartenders:
  • Tim Holloway
  • Piet Souris
  • Frits Walraven

Call servlet from java class and redirect to jsp page

 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 300
Eclipse IDE Oracle Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
To dispatch a request from servlet to JSP you can use RequestDispatcher.
 
Rancher
Posts: 43011
76
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
limitha adulla
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Rancher
Posts: 43011
76
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What have you tried, and what happened? Post the code.
 
Marshal
Posts: 25176
64
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi Ulf Dittmer

can please tell me how to use setFollowRedirects(true) method.
 
His brain is the size of a cherry pit! About the size of this ad:
Java file APIs (DOC, XLS, PDF, and many more)
https://products.aspose.com/total/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!