File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
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


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
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
Author

Not able to access hidden fields in servlet

nazar hussain
Greenhorn

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

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

Joined: Jan 10, 2002
Posts: 60046
    
  65

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] [Bear's FrontMan] [About Bear] [Books by Bear]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Not able to access hidden fields in servlet
 
Similar Threads
Why can't I get the Vector value in jsp(ModalDialog)?
Servlet API 2.2
Need Some Help Here
retrieve value at servlet from javascript.
How to distinguish between two different button clicks on servlet