aspose file tools*
The moose likes JSP and the fly likes Need Help with JSP & Servlet Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "Need Help with JSP & Servlet" Watch "Need Help with JSP & Servlet" New topic
Author

Need Help with JSP & Servlet

Randall Stevens
Ranch Hand

Joined: Jul 01, 2003
Posts: 65
I have a very simple JSP that I am trying to get to work. But first a little history:
I have an HTML page that POSTs to my server. A servlet takes the data and performs several functions on the values and does a response.setAttribute(myAttribute,value); then does a reponse.getRequestDispatcher("webfiles/my.jsp")
my.jsp is very generic
<html>
<head>
</head>
<body>
<FORM ACTION="/examples/servlet/AnotherServlet" ENCTYPE=
"multipart/form-data" >
<% String myAttrib = request.getParameter(myAttribute) %>
<input type="text" name="TextInput" size=6 maxlength=6>
<input type="submit" value="submit" >
</body>
</html>
The problems I am having are:
1. How do I know that the attribute is being set?
2. Am I using the getRequestDispatcher correctly?
3. How do I pass back both the TextInput parameter and the myAttrib parameter?
It has been three years since I have done this, I do not seem to remember everything I need to get it correctly functioning.
Randall
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60078
    
  65

How do I know that the attribute is being set?

Within your current JSP you don't. The getParameter() method is used to retrieve submitted request parameters (form submission or query string). What you want is getAttribute().
Am I using the getRequestDispatcher correctly?

Assuming the URL is correct, half correctly. After creating the dispatcher you need to forward to the JSP page.
How do I pass back both the TextInput parameter and the myAttrib parameter?

The TextInput will become part of the form submission data (retrieved in the next action by getParameter()). To also cause the myAttrib value to be passed along, generate a hidden input with that data in the form.
bear
[ October 09, 2003: Message edited by: Bear Bibeault ]

[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Randall Stevens
Ranch Hand

Joined: Jul 01, 2003
Posts: 65
1. How do I get the relative path for the url to be correct? I am using a default configuration of Tomcat 4.0.4, the servlet is in the 'webapps/web-inf/classes' directory, the jsp is in 'webapps/root' directory.
2. Can you show me the correct usage of response.getAttribute() in my example?
In using the 'Core Web Programming, Second Edition' by Marty Hall and Larry Brown, the example they are using to retrieve attributes is <jsp:useBean id="key" scope="session"> . I am not sure if that is correct for my situation.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Need Help with JSP & Servlet
 
Similar Threads
problem with form submission
Internationalization (specifically with Chinese characters)
Context Path Still Won't Display an Image
&nbsp; ...
Servlet getParameter