| Author |
data from servlet to jsp
|
Beth Smith
Greenhorn
Joined: Feb 27, 2012
Posts: 3
|
|
I am a beginner in programming with servlets and jsp. I am creating a servlet and in the servlet I am creating an attribute and sending its value to a jsp page.
The attribute's value is then displayed on the jsp page. However, when displaying the value, null is being displayed and I cannot understand why.
below is the code for the servlet and the jsp:
ServletTest.java
index.jsp
|
 |
Swastik Dey
Ranch Hand
Joined: Jan 08, 2009
Posts: 1188
|
|
|
Which one is executed first, servlet or jsp? Another point, avoid using java code in jsp. Use JSTL/EL or custom tags etc.
|
Swastik
|
 |
William Brogden
Author and all-around good cowpoke
Rancher
Joined: Mar 22, 2000
Posts: 12265
|
|
Attributes and Parameters are NOT the same thing.
Parameters are extracted from the user's request - Attributes can be attached to a request by your code.
Your code is not allowed to add Parameters to a request, the map of parameters is immutable.
See the JavaDocs for javax.servlet.ServletRequest
Bill
|
Java Resources at www.wbrogden.com
|
 |
Rob Spoor
Sheriff
Joined: Oct 27, 2005
Posts: 19216
|
|
|
Also, your form action is incorrect. It should be "${pageContext.request.contextPath}/ServletTest". Without those {}, the $ only applies to pageContext, and the form action would be the page context's String representation followed by ".request.contextPath/ServletTest".
|
SCJP 1.4 - SCJP 6 - SCWCD 5
How To Ask Questions How To Answer Questions
|
 |
Beth Smith
Greenhorn
Joined: Feb 27, 2012
Posts: 3
|
|
thanks for your replies. I modified the getAttribute and setAttribute methods, however with the "${pageContext.request.contextPath}/ServletTest" I am getting an error telling me that there is a whitespace in path and I cannot understand why.
index.jsp
ServletTest.java
|
 |
Rob Spoor
Sheriff
Joined: Oct 27, 2005
Posts: 19216
|
|
|
What's the name of your web application?
|
 |
Bear Bibeault
Author and ninkuma
Marshal
Joined: Jan 10, 2002
Posts: 56157
|
|
|
Scriptlets are dead. Use the EL. To access the value of a scoped variable named "hello" you would use ${hello}.
|
[Smart Questions] [JSP FAQ] [Books by Bear] [Bear's FrontMan] [About Bear]
|
 |
Beth Smith
Greenhorn
Joined: Feb 27, 2012
Posts: 3
|
|
|
thanks for your replies, it worked now
|
 |
 |
|
|
subject: data from servlet to jsp
|
|
|