This week's book giveaway is in the Android forum.
We're giving away four copies of Head First Android and have David & Dawn Griffiths on-line!
See this thread for details.
Win a copy of Head First Android this week in the Android forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Rob Spoor
  • Bear Bibeault
Saloon Keepers:
  • Jesse Silverman
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • Al Hobbs
  • salvin francis

problems adding new parameters to a request

 
Ranch Hand
Posts: 58
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Sheriff
Posts: 13411
Firefox Browser VI Editor Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Attributes are not the same thing as parameters.

To retrieve request attributes use:
request.getAttribute("total")
 
Sven Anderson
Ranch Hand
Posts: 58
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 1026
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
use Expression Language(EL)

${total} or ${requestScope.total}
 
Sven Anderson
Ranch Hand
Posts: 58
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
You showed up just in time for the waffles! And this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic