• 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
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Need Help with JSP & Servlet

 
Ranch Hand
Posts: 65
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Sheriff
Posts: 67746
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

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 ]
 
Randall Stevens
Ranch Hand
Posts: 65
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
reply
    Bookmark Topic Watch Topic
  • New Topic