Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Not able to access hidden fields in servlet

 
nazar hussain
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
Currently i am coding a web application program in servlets. I have a form having fields in servlet which adds a record . I have a ADD button in the form which when clicked causes the entered record to be displayed in a table in the same servlet. The validations for the field are done in a javascript and i am using a hidden variable "action" in the javascript to which i am assigning "ADD" if add button is clicked .If i am trying to access the same hidden field in the servlet using request.getParameter i am getting "null" value in the servlet. How to resolve the issue .Currently i am using Eclipse Galileo IDE for development purpose.Any help provided on it would be greatly appreciated .


Code in the javascript

--------------------------------------------------------------------------------

function fnValidate{

document.BookForm.submitform.value = "ADD"

}

Code in the servlet

--------------------------------------------------------------------------------
protected void doService(HttpServletRequest request, HttpServletResponse response){

// The Form displayed using servlet
out.println("<script language=\"javascript\" src=\"validate_Book.js\"></script>");
out.println("<form name=\"BookForm\" method=\"post\" action=\"SaveBookServlet\">");
// The fields in the form
out.println("<input type=\"hidden\" name=\"submitform\" id=\"submitform\">");
.........
String event = (String) request.getParameter("submitform");
System.out.println("event is "+submitform);

/* The above string is getting printed as null in the eclipse console */

if(event != null){
if(event.equals("ADD"){

Display the record
}
else if(event.equals("BACK"){
Go to previous page
}
}
 
Mark E Hansen
Ranch Hand
Posts: 650
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why are you overriding the doService method? You should not do this. Instead, you should implement the doGet and doPost methods.

This is a standard debugging issue. If you believe the problem is in the use of hidden fields, then create a simple test HTML form which uses hidden fields and an 'action' that invokes the servlet. This will prove that hidden fields work, and you need to look elsewhere for the cause.

I would guess there is something wrong with the way you're doing the javascript. I would eliminate that as well and see what happens.

Good luck.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64843
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please be sure to use code tags when posting code to the forums. Unformatted code is extremely hard to read and many people that might be able to help you will just move along to posts that are easier to read. Please read this for more information.

You can go back and change your post to add code tags by clicking the button on your post.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic