Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

passing parameters from jsp to servlet

 
Shobana Sukumar
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Rancher
Posts: 42967
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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é
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Also make sure that the name you pass to getParameter is *really* the name of the input field in your jsp page.
 
Abhinit Saxena
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 181
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Checking the null value is always a good practice..I always follow the rule that Saxena suggested.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic