my dog learned polymorphism
The moose likes Servlets and the fly likes Not able to access hidden fields in servlet Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "Not able to access hidden fields in servlet" Watch "Not able to access hidden fields in servlet" New topic

Not able to access hidden fields in servlet

nazar hussain

Joined: Feb 11, 2010
Posts: 1
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){

Display the record
else if(event.equals("BACK"){
Go to previous page
Mark E Hansen
Ranch Hand

Joined: Apr 01, 2009
Posts: 650
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

Joined: Jan 10, 2002
Posts: 63865

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.

[Asking smart questions] [About Bear] [Books by Bear]
I agree. Here's the link:
subject: Not able to access hidden fields in servlet
It's not a secret anymore!