File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Servlets and the fly likes HTML username password sending to servlet Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "HTML username password sending to servlet" Watch "HTML username password sending to servlet" New topic

HTML username password sending to servlet

nash avin
Ranch Hand

Joined: Nov 13, 2003
Posts: 96
Hi all,
I wanted to know given a html page that contains "username" and "password" options.I want to send the values that are being typed in the username and password options to a servlet.
Kindly let me know how this is done in detail.I have written a little piece of code to do this.The code is below

In the form tag I am finding it difficult as to how it can be done.
Kindly let me know.
Hoping to hear from you.
Thanking you
Scott Duncan
Ranch Hand

Joined: Nov 01, 2002
Posts: 364
This seems fine to me. Now in the AuthenticateServlet2 servlet's doGet method, you can retrieve the values by:
String username = request.getParameter("username");
String pw = request.getParameter("password");
What problem are you having, specifically?

No more rhymes! I mean it!<br /> <br />Does anybody want a peanut?
Billybob Marshall
Ranch Hand

Joined: Jan 27, 2004
Posts: 202
A couple of things to consider, since you're dealing with "sensitive" information (user names and passwords):
1) Use "POST" instead of "GET" - otherwise the values get sent as clear text on the URL, regardless of whether you're using SSL or not.
2) Use SSL so that the values aren't sent as clear text in the POST headers.
Craig Jackson
Ranch Hand

Joined: Mar 19, 2002
Posts: 405
Also since the the "POST" method is better way to go because the data will not be seen as a part of the URL. You need to put your code in the doPost method instead of the doGet method. Also it is very common to forward doPost and doGet paramaters to a single method, something similar to below:

or you can do this:

I hope this helps
I agree. Here's the link:
subject: HTML username password sending to servlet
jQuery in Action, 3rd edition