This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
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 Android Security Essentials Live Lessons this week in the Android 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: 643
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: 60785
    
  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]
 
Consider Paul's rocket mass heater.
 
subject: Not able to access hidden fields in servlet
 
Similar Threads
How to distinguish between two different button clicks on servlet
Servlet API 2.2
Why can't I get the Vector value in jsp(ModalDialog)?
retrieve value at servlet from javascript.
Need Some Help Here