• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Liutauras Vilda
  • Paul Clapham
Sheriffs:
  • paul wheaton
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Piet Souris
Bartenders:
  • Mike London

data from servlet to jsp

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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

 
Bartender
Posts: 2270
20
Android Java ME Eclipse IDE Java
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Author and all-around good cowpoke
Posts: 13078
6
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Sheriff
Posts: 22716
129
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Posts: 22716
129
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What's the name of your web application?
 
Sheriff
Posts: 67695
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thanks for your replies, it worked now
 
reply
    Bookmark Topic Watch Topic
  • New Topic