aspose file tools*
The moose likes Servlets and the fly likes data from servlet to jsp Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "data from servlet to jsp" Watch "data from servlet to jsp" New topic
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
Rancher

Joined: Jan 08, 2009
Posts: 1477
    
    6

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: 12784
    
    5
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

Joined: Oct 27, 2005
Posts: 19693
    
  20

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 - OCEEJBD 6
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: 19693
    
  20

What's the name of your web application?
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61206
    
  66

Scriptlets are dead. Use the EL. To access the value of a scoped variable named "hello" you would use ${hello}.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Beth Smith
Greenhorn

Joined: Feb 27, 2012
Posts: 3
thanks for your replies, it worked now
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: data from servlet to jsp