aspose file tools*
The moose likes Servlets and the fly likes problems adding new parameters to a request Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "problems adding new parameters to a request" Watch "problems adding new parameters to a request" New topic
Author

problems adding new parameters to a request

Sven Anderson
Ranch Hand

Joined: Apr 14, 2004
Posts: 58
Hi all,

I'm having the following problem. I've got a html form submitting a few input fields(parameters) to a dispatcher servlet that uses a RequestDispatcher objec to forward the request to a Servlet taking care of the business logic. In this servlet I'm trying to add a

request.setAttribute

to the Request object. A RequestDispatcher is again forwarding the request to a JSP page to output the result. My JSP page successfully outputs the parameters from the html form however the attribute I added in my business logic servlet doesn't seem to have been added.
This is the code from my business logic servlet where I'm adding a new attribute.

request.setAttribute("total","10");
RequestDispatcher router = request.getRequestDispatcher("/result.jsp");
router.include(request, response);

In my JSP I'm outputing my parameters the following way
String a = request.getParameter("formfield1");
String b=request.getParameter("total");

out.println("value of " +a);
out.println("value of " +b);

I actually also used the request.getParameterNames() to see which attributes were included in the request and all attributes were there except the one I add in my servlet.

If anyone can shed some light over this annoying problem, Pls let me know
Many thanks
Erik
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

Attributes are not the same thing as parameters.

To retrieve request attributes use:
request.getAttribute("total")


Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
Sven Anderson
Ranch Hand

Joined: Apr 14, 2004
Posts: 58
Hi there!!

Ahh didn't see this when I was programming yesterday. Probably sent too many hours in from of the computer.

ps. do you know how I can output attributes using JSTL?

Thanks very much!!!


Erik
Vishnu Prakash
Ranch Hand

Joined: Nov 15, 2004
Posts: 1026
use Expression Language(EL)

${total} or ${requestScope.total}


Servlet Spec 2.4/ Jsp Spec 2.0/ JSTL Spec 1.1 - JSTL Tag Documentation
Sven Anderson
Ranch Hand

Joined: Apr 14, 2004
Posts: 58
Hi,

Excellent!! thanks very much.
Didn't know I could just use total attribute straight away using EL.
This saved me alot of time.

Thanks again
Erik
 
Don't get me started about those stupid light bulbs.
 
subject: problems adding new parameters to a request