File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes JSP and the fly likes Getting Param values from JSP tp servlet Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "Getting Param values from JSP tp servlet" Watch "Getting Param values from JSP tp servlet" New topic
Author

Getting Param values from JSP tp servlet

Rohit Kumar
Ranch Hand

Joined: Jul 19, 2007
Posts: 35
Hi,
I have a form with text box. When the user enters Name and clicks button, am calling a servlet.
What I need is �when the user enters name and clicks Submit..i want this name to be available on Servlet. I am doing the following way..but still it is showing null.
Can anyone help .
<form name="userLogin" ACTION="UserValidation" METHOD="POST">

<tr> User Name
<td><input type="text" name=�userName" id="userName" ></td>
</tr>
This is how I am getting in Servlet

userName is showing null here. How could I get the userName that is entered to form??


Thanks

[BPSouther: Added code tags]
[ September 11, 2007: Message edited by: Ben Souther ]
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

Can you post the entire form?


Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
Sri Anand
Ranch Hand

Joined: Mar 06, 2005
Posts: 392
are you using Struts, I see Action in form attributes if yes, you can get that from form(ActionForm) object
Rohit Kumar
Ranch Hand

Joined: Jul 19, 2007
Posts: 35
I am not using Struts. I am calling a servlet from this JSP and so is Action attribute in my form.

Below is my complete form

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>User Login</title>
</head>

<body>

<center>

<form name="userLogin" ACTION="UserValidation" METHOD="POST">

<tr> User Name
<td><input type="text" name=�userName" id="userName" ></td>
</tr>
<tr> Employer ID
<td><input type="text" name=�empId" id="empId" ></td>
</tr>
<tr>
<td><input type="SUBMIT" value="Submit" ></td>
</tr>

</form>


</center>
</body>
</html>
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61758
    
  67

Originally posted by Raghunandan Mamidala:
are you using Struts
Please do not assume that anyone posting in the JSP forum is using Struts unless they specifically mention it, or otherwise reveal that they are using it. Thanks.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

Found it.


[ September 11, 2007: Message edited by: Ben Souther ]
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

Rohit,

This was tough to spot because you posted the code without UBB Code tags.
These tags help to preserve whitespace and make your code easier to read.
It also uses a mono spaced font (every character is the same width, including whitespace) which makes this bug stand out a lot more.

I just added them to your original post.
Had you done that when you posted it, someone surely would have found this bug sooner for you.


Look at the difference
Without:
String userName = request.getParameter("userName ");

With:

See:
code tags
[ September 11, 2007: Message edited by: Ben Souther ]
Rohit Kumar
Ranch Hand

Joined: Jul 19, 2007
Posts: 35
Hi Ben,

Thanks for your time. The problem is even after removing the space, i am still getting null value. It is getting the value that I printed in the form.

Any other sugestions.

Next time, i will see that I put the code in UBB tags.
Rohit Kumar
Ranch Hand

Joined: Jul 19, 2007
Posts: 35
oops...it is not getting the value that I printed int he form.
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

Everything else looks fine.
Are you sure you recompiled and restarted the app after removing the space?
Rohit Kumar
Ranch Hand

Joined: Jul 19, 2007
Posts: 35
Hey Ben,

I deleted cache, recompiled..and restarted. It is still getting the null value. I have no clue why it is showing null still.


Any suggestions??
Thanks,
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

Paste this into the top of your doPost method, compile, restart, submit the form and, go look at your logs to see whats there. Post it here.



You may have to import java.util.*;
[ September 11, 2007: Message edited by: Ben Souther ]
Rohit Kumar
Ranch Hand

Joined: Jul 19, 2007
Posts: 35
Hi Ben,

It is not even going to while loop..

currently our server is down..I will post you the content in log file right I am good with our server.

Thanks for your time Ben..
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14688
    
  16

What is this double quotation ?

<input type="text" name=userName" id="userName" ></td>
[ September 12, 2007: Message edited by: Christophe Verre ]

[My Blog]
All roads lead to JavaRanch
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

Originally posted by Christophe Verre:
What is this double quotation ?

name=userName


Yes, if you increase the font size enough, it becomes clear that you're using something other than a regular double quote here.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Getting Param values from JSP tp servlet