thank you. That was my problem. I guess I could only get values that are inputs and not text or labels??
Will -----Original Message----- From: Gennis Emerson [mailto:[EMAIL PROTECTED]] Sent: Friday, January 18, 2002 6:39 PM To: [EMAIL PROTECTED] Subject: Re: passing parameters from jsp to servlet "Kwan, William" wrote: > > Hi, > I'm going from one jsp page to another jsp page and then the > servlet. I"m having a bit of a problem passing a parameter > from a jsp page to a servlet. I print out the variable in the > jsp page and I get a value but when I print it from a servlet, > I get NULL. > > Any ideas?? > > Here is what I'm using: > > jsp page: > <form action='servlet/processServlet' method='POST'> > ... > request.setAttribute("txtbox",ponumber); > > </form> > > in servlet > > public void doPost(HttpServletRequest, request, HttpServletResponse > response) throws IOException, ServletException > { > response.setContentType("text/html"); > PrintWriter out=response.getWriter(); > > String ponum = (String) request.getAttribute("txtbox"); > out.println("ponum=" + pponum); > > } It looks like what you have is a JSP page with an HTML form which is sent to the browser and then submitted to your servlet. If so, you need to pass the value to the browser in the HTML page: <form action='servlet/processServlet' method='POST'> <input type="hidden" name="txtbox" value="<%= ponumber %>"> </form> and retrieve it in your servlet as a request parameter: public void doPost(HttpServletRequest, request, HttpServletResponse response) throws IOException, ServletException { //... String ponum = request.getParameter("txtbox"); } A request attribute only lasts until the request is completed, which in this case means that the request attribute you set in the JSP page is destroyed when the JSP sends its response to the browser. When you submit the form to the servlet, you're creating a completely new request. ___________________________________________________________________________ To unsubscribe, send email to [EMAIL PROTECTED] and include in the body of the message "signoff SERVLET-INTEREST". Archives: http://archives.java.sun.com/archives/servlet-interest.html Resources: http://java.sun.com/products/servlet/external-resources.html LISTSERV Help: http://www.lsoft.com/manuals/user/user.html ___________________________________________________________________________ To unsubscribe, send email to [EMAIL PROTECTED] and include in the body of the message "signoff SERVLET-INTEREST". Archives: http://archives.java.sun.com/archives/servlet-interest.html Resources: http://java.sun.com/products/servlet/external-resources.html LISTSERV Help: http://www.lsoft.com/manuals/user/user.html
