This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan 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 Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "passing parameters from jsp to servlet" Watch "passing parameters from jsp to servlet" New topic
Author

passing parameters from jsp to servlet

Shobana Sukumar
Greenhorn

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
Marshal

Joined: Mar 22, 2005
Posts: 41123
    
  45
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 ]

Ping & DNS - my free Android networking tools app
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14687
    
  16

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
Greenhorn

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

in JSP/HTML
<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: 166
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: http://aspose.com/file-tools
 
subject: passing parameters from jsp to servlet
 
Similar Threads
communication Between two servlets
Passing a String[] from jsp to servlet
referencing a variable in a jsp from a servlet
response from servlet
Session expires ,user session expires when online