This week's book giveaways are in the Refactoring and Agile forums.
We're giving away four copies each of Re-engineering Legacy Software and Docker in Action and have the authors on-line!
See this thread and this one for details.
Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

passing data from jsp to servlet using mvc and jdbc

 
Lloyd Liongson
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Im currently new in java ee. I need help on how to pass my data from jsp to my servlet to fil up my query. Whenever i run, the error is being catch and i print out the exception. It says java.null.exception.. I couldn't find out where my error is..please help me... thanks..

Here is my code:

UpdateProductServlet.java


and my ProductDao.java



and this is my ProductById.jsp

 
Steve Luke
Bartender
Posts: 4181
21
IntelliJ IDE Java Python
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Any of your form inputs which are disabled do not get submitted, so they never reach the servlet as request parameters. Take out all the disabled attributes for the data you want to show up in the request.

Also you have this in your Servlet for error handling:

That is very bad practice: You should print the exception's message and stack trace to a log file at least, and not just the e.toString() to the page's output. That would help you figure out which parameter is null.
 
Lloyd Liongson
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi. I have a button there when the edit button (javascript function)is click, the fields will be enabled allowing user to edit the fields except for the id. then the update button will appear for calling the servlet.
 
sourav jain
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I carefully read your code for servlets and jsp . My point of view null pointer exception error is run time error.

1) In UpdateProductServlet.java , your are not accessing all parameters from jsp page.


you can check all values whether these are coming or not. using followings statement

like as
System.out.println(description);
System.out.println(price);
System.out.println(size);
System.out.println(aisle_id);
System.out.println(id);

If any one above statements will display NULL or null , it means that no value is transfer from jsp to servlet.

 
Lloyd Liongson
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi. i have solve the problem, i forgot to include form action in my jsp..
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic