File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Servlets and the fly likes passing variables from Servlet to JSP Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "passing variables from Servlet to JSP" Watch "passing variables from Servlet to JSP" New topic

passing variables from Servlet to JSP

Med Shabe
Ranch Hand

Joined: May 08, 2001
Posts: 84
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

Joined: Apr 02, 2001
Posts: 18
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

Sylvia Allen<br />
Craig Jackson
Ranch Hand

Joined: Mar 19, 2002
Posts: 405
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

Joined: May 08, 2001
Posts: 84
Moose's eye...
both the "/" and the space were the problems.
Thank you.
Matthew Phillips
Ranch Hand

Joined: Mar 09, 2001
Posts: 2676
For future reference, please refrain from double posting. Thanks.

Matthew Phillips
subject: passing variables from Servlet to JSP
Similar Threads
JSP Scripting Elements
Setting dynamic parameter values?
RequestDispatcher include throws IllegalStateException?
servlet init parameters for jsp
Including a JSP page from a different Web Application