File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

data from servlet to jsp

 
Beth Smith
Greenhorn
Posts: 3
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Rancher
Posts: 1601
5
Android Java Java ME
  • 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Which one is executed first, servlet or jsp? Another point, avoid using java code in jsp. Use JSTL/EL or custom tags etc.
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13048
6
  • 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Rob Spoor
Sheriff
Pie
Posts: 20388
46
Chrome Eclipse IDE Java Windows
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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".
 
Beth Smith
Greenhorn
Posts: 3
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 20388
46
Chrome Eclipse IDE Java Windows
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What's the name of your web application?
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64196
83
IntelliJ IDE Java jQuery Mac Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Scriptlets are dead. Use the EL. To access the value of a scoped variable named "hello" you would use ${hello}.
 
Beth Smith
Greenhorn
Posts: 3
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks for your replies, it worked now
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic