Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

problems adding new parameters to a request

 
Sven Anderson
Ranch Hand
Posts: 58
  • Mark post as helpful
  • send pies
  • 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
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • 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
  • 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
 
Vishnu Prakash
Ranch Hand
Posts: 1026
  • Mark post as helpful
  • send pies
  • 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
  • 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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic