This week's book giveaway is in the Java in General forum.
We're giving away four copies of Think Java: How to Think Like a Computer Scientist and have Allen B. Downey & Chris Mayfield on-line!
See this thread for details.
Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

passing variables from Servlet to JSP

 
Med Shabe
Ranch Hand
Posts: 84
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can someone show me a sample for passing variables from servlets to JSPs? This is what I have in my servlet:

And this is my JSP:

Hopefully someone will point out the goof up!
Thanks much.
 
Sylvia Allen
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I hope this isn't a really dumb answer, but it looks to me as if you have a typo--
<% = Attr1 %>
There shouldn't be a space between the % and the =.
<%= Attr1 %>
Though for all I know, it works just fine with the space there; I've never tried it that way. Somebody just shoot me if this is a clueless answer.
- SA
 
Craig Jackson
Ranch Hand
Posts: 405
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I believe the problem is that you are getting the RequestDispather from the ServletContext interface. Which implies that the path must begin with a "/", which is interpreted relative to the current context root.
rd = getServletContext().getRequestDispatcher("/newJSP.jsp");
This becomes a URL relative to the root of the webapp.
 
Med Shabe
Ranch Hand
Posts: 84
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
WOW,
Moose's eye...
both the "/" and the space were the problems.
Thank you.
 
Matthew Phillips
Ranch Hand
Posts: 2676
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Med,
For future reference, please refrain from double posting. Thanks.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic