Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

JSP to Servlet hidden text passing

Posted on 2003-03-31
5
Medium Priority
?
783 Views
Last Modified: 2013-11-24
I currently have a web application that takes user input from a jsp page and processes that information within a servlet.  I need to check user input, and if an error is detected forward back to the user input jsp.  I also need to indicate the errors that they made.  I thought that this would be relatively simple to do.  I tried checking for errors in the servlet and then setting the text of a hidden input to indicate that an error has occured.

The problem that I'm having is that the hidden text box seems to be reset whenever a forward command is sent to it.  Whenever the jsp checks for the hidden text it finds an empty string.  I have logging setup, and while in the servlet I can tell that the hidden text was correctly set.  However as soon as its forwarded the hidden text is reset.

How can I check for errors in the servlet and pass a value to the jsp to indicate that some input was not correctly entered?

Thanks in advance,
Michael Crutcher
0
Comment
Question by:mcrutcher
  • 2
  • 2
5 Comments
 
LVL 86

Expert Comment

by:CEHJ
ID: 8239858
It is often better to validate client-side using JavaScript, as this saves a trip to the server.
0
 

Author Comment

by:mcrutcher
ID: 8239944
I understand that there are some instances where verifying on the client side is better.  However the jsp page is maintained by someone else and they don't know java or java script.  I don't want to polute the jsp with a bunch of code.  Its only a jsp so that I can dynamically fill list boxes with a bean call.

I think I figured it out, but its pretty wierd.  I've been calling getParameter(String) on the request object to get the value.  This works for all of the text and list boxes but returns a blank string on a hidden input element.  The method getAttribute(String) on the request object returns the correct value.  So I fixed it, but its still pretty wierd.  Can anyone tell me the difference between request.getAttribute(String) and request.getParameter(String)?

Michael Crutcher
0
 
LVL 2

Accepted Solution

by:
amit_chauhan earned 750 total points
ID: 8240874
request.getParameter () returns the parameters that make the query string of an http request. These are the parameters that are passed from a jsp/html page by tags like <input type="text">.
You cannot set parameters programatically.

However, java provides methods setAttribute () and getAttribute () to set your own parameters (attributes) in the request, which can be accessed by another servlet (jsp) where the request is forwarded to.

But as a new request object is created for each http request, these attributes have the life time of the request.

They will be available to a forwarded jsp/servlet as the request object is the same, but if you are redirecting to a jsp/servlet, then its a new request, and those attributes and parameters will be lost.


Hope that helps
Thanks
Amit
0
 

Author Comment

by:mcrutcher
ID: 8240910
That works as an answer to me, but I have a couple of questions about your response if you don't mind.

You cannot set parameters programatically.
what is setParameter(String name, String value) for?

So an attribute has no direct relation to input from the user?  I mean I don't need to create a hidden box, I can just make up the attribute in code?
0
 
LVL 2

Expert Comment

by:amit_chauhan
ID: 8241128
I dont know where are you seeing the method setParameter (). I dont see that anywhere in the javadocs.

Second, yes, you are right, attribute has no relation to input from the user. So you dont need to create a hidden text box for it.

Hope that helps
Thanks
Amit
0

Featured Post

[Webinar On Demand] Database Backup and Recovery

Does your company store data on premises, off site, in the cloud, or a combination of these? If you answered “yes”, you need a data backup recovery plan that fits each and every platform. Watch now as as Percona teaches us how to build agile data backup recovery plan.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
Viewers learn about the scanner class in this video and are introduced to receiving user input for their programs. Additionally, objects, conditional statements, and loops are used to help reinforce the concepts. Introduce Scanner class: Importing…
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
Suggested Courses
Course of the Month11 days, 19 hours left to enroll

564 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question