This week's giveaway is in the Spring forum.
We're giving away four copies of REST with Spring (video course) and have Eugen Paraschiv on-line!
See this thread for details.
The moose likes Servlets and the fly likes passing parameters from jsp to servlet Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of REST with Spring (video course) this week in the Spring forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "passing parameters from jsp to servlet" Watch "passing parameters from jsp to servlet" New topic

passing parameters from jsp to servlet

Shobana Sukumar

Joined: Nov 24, 2005
Posts: 17
i have a jsp and need to pass values from that jsp to servlet.

im accessing with request.get Parameter,,...the problem is one of the value or field in the table has a very long value that is 000000000000000000000000000000000000000000000000000..... so its creating nullpointer exception while retriving ...wot to do?
Ulf Dittmer

Joined: Mar 22, 2005
Posts: 42959
Are you actually trying to pass a value from a JSP page to a servlet, i.e. using Java code? Or is the value in an HTML form in a page that was generated by a JSP page, and you're trying to submit the form to a servlet?

Assuming the latter, the length of the value submitted is irrelevant. By itself it would not cause a NullPointerException. What is returned if -in your servlet- you call ?
[ January 11, 2006: Message edited by: Ulf Dittmer ]
Christophe Verré

Joined: Nov 24, 2005
Posts: 14688

Also make sure that the name you pass to getParameter is *really* the name of the input field in your jsp page.

[My Blog]
All roads lead to JavaRanch
Abhinit Saxena

Joined: Jan 10, 2006
Posts: 18
best practice to go with parameter:

1) always try to create same variable name and the parameter name like

<input type="text" name="userName"/>

in servlet:
String userName = request.getParameter("userName");

2) always check for null before using any variable got by getParameter

String userName = request.getParameter("userName");
if(userName!=null && .....)
Tauri Valor
Ranch Hand

Joined: Aug 03, 2005
Posts: 180
Checking the null value is always a good practice..I always follow the rule that Saxena suggested.

A Moment's insight is sometimes worth a Life's experience.
I agree. Here's the link:
subject: passing parameters from jsp to servlet
It's not a secret anymore!