This week's giveaway is in the EJB and other Java EE Technologies forum.
We're giving away four copies of EJB 3 in Action and have Debu Panda, Reza Rahman, Ryan Cuprak, and Michael Remijan on-line!
See this thread for details.
The moose likes Servlets and the fly likes Help needeed on URL and URLConnection classes Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "Help needeed on URL and URLConnection classes" Watch "Help needeed on URL and URLConnection classes" New topic
Author

Help needeed on URL and URLConnection classes

praveen sainath
Greenhorn

Joined: Nov 28, 2006
Posts: 9
Hi ppl,
I have an requirment to call an servlet from a jsp, but that servlet requires authentication, i have the user information in the jsp.
My requirment is to connenct to the servlet with user information to login first, using URL or URLConnection classes and then using the same connection I have to call the servlet again with different parameters..

for example ,
If "/publish" is my servlet I will pass
?module=com.med.phd.LoginModule&action=verify&user=xxx&password=yyy
first
and then
call the same "/publish" servlet with different set of parameters

Can anyone help me on this pls..it is very urgent!!!
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336

Moving to Servlets forum...


JavaRanch FAQ HowToAskQuestionsOnJavaRanch
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

Originally posted by praveen sainath:
...Can anyone help me on this pls..it is very urgent!!!


praveen sainath,
Welcome to JavaRanch!

In an effort to help you get the most from our forums, we've compiled a
list of tips for asking questions here. You can find the list in our
FAQ section here.
In particular please see:
EaseUp to learn how putting "Urgent" in your post or subject line can actually slow down or eliminate responses to your question altogether.

Again, welcome to JavaRanch and good luck with your question.
-Ben


Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12675
    
    5
I have an requirment to call an servlet from a jsp, but that servlet requires authentication,


What does the servlet do once it has authenticated a user?

If it creates a session, the cookie identifying that session will be passed back in the response to the authentication request. Your task will be to locate that cookie and send it with subsequent requests so the servlet will consider the user authenticated.

The open source HttpClient toolkit might be what you need, or you can try to handle the cookie directly by examining the header sent in the response.

Note: if the url you address starts with http:// you will actually be dealing with a HttpURLConnection - see the java.net package documentation.

Bill


Java Resources at www.wbrogden.com
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 39547
    
  27
I'm confused. Does "calling the servlet from a JSP" mean that the URL is part of a link or form submit on a web page? If so, how would you use client-side Java classes?

Can you pass all required parameters to the LoginModule URL, and have that forward the request to whichever servlet it's supposed to go to?


Ping & DNS - updated with new look and Ping home screen widget
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Help needeed on URL and URLConnection classes
 
Similar Threads
Help required in URL class
Help on URL class
basic authentication
Passing Input parameters in Struts
URLConnection problem