tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Scott Petersen <SPeter...@pangaea.ca>
Subject RE: Passing parameters to a bean from a JSP
Date Mon, 03 Apr 2000 22:39:29 GMT
If you are doing this from within a JSP page then you shouldn't have to do
anything at all to initialise the request, session, out, or response
objects. They are all defined for you. Would it be possible for you to post
some of your code. It could be something as simple as the incorrect form is
being submitted, the form objects are all disabled (don't laugh I did that
one), a redirect is happening but not passing on the request object. etc.
etc.

Cut and paste the following code into a file called mytest.jsp. If it works
then everything is working as expected and there is likely a bug in your
code.

Good Luck
Scott Petersen
Programmer/Analyst
Pangaea Systems
speterse@pangaea.ca
250-360-0111

----Cut Here----
<html>
<body>
<%@ page import="java.util.*" %>
<% //Use this to list all the form items and their values.
Enumeration enum = request.getParameterNames(); 
while (enum.hasMoreElements()) 
{
	String paramName = (String) enum.nextElement();
	out.println(paramName + ":" + 
	request.getParameter(paramName) + "<br>");
};
%>
<form method="post" name="frmMyTest" action="mytest.jsp">
First Name:<input type="text" name="txtFirstName"
value="<%=request.getParameter("txtFirstName")%>"><br>
Last Name:<input type="text" name="txtLastName"
value="<%=request.getParameter("txtLastName")%>"><br>
Address:<input type="text" name="txtAddress1"
value="<%=request.getParameter("txtAddress1")%>"><br>
<input type="submit" value="Try It">
</form>
</body>
</html>
----Cut Here----

> -----Original Message-----
> From: Jerry Thomas [mailto:jerry_thomas@hotmail.com]
> Sent: Monday, April 03, 2000 3:17 PM
> To: tomcat-user@jakarta.apache.org
> Subject: RE: Passing parameters to a bean from a JSP
> 
> 
> 
> The request.getParameterNames() comes back with no values. Is there 
> something I need to do to initialize the request object?
> 
> >Try
> >
> >     String parString = 
> request.getParameter("nameOfFormItem"); //Use this 
> >to
> >get the values of individual form items.
> >
> >
> ><% //Use this to list all the form items and their values.
> >     Enumeration enum = request.getParameterNames(); //Put 
> all parameters
> >into an enumeration object
> >     while (enum.hasMoreElements()) //Iterate throught the 
> enumeration.
> >     {
> >       String paramName = (String) enum.nextElement(); //Get 
> the name of 
> >the
> >next parameter
> >       out.println(paramName + ":" + 
> request.getParameter(paramName) +
> >"<br>"); //Get the value of the parameter and print it to the screen
> >     };
> >%>
> >
> >That's what we use with Tomcat 3.0 and 3.1 and they work great.
> >
> >Cheers
> >Scott Petersen
> >Programmer/Analyst
> >Pangaea Systems
> >speterse@pangaea.ca
> >250-360-0111
> >
> > >
> > > The request.getParameterNames() and request.ParameterValues()
> > > are returning
> > > null. I am pulling values from the FORM using JavaScript so I
> > > know that the
> > > fields are there and that they have values. How do I
> > > initialize the request
> > > object so that I can pull FORM values from it?
> > >
> > >
> > > >
> > > >Your FORM parameters and INPUT fileds are sent to your JSP
> > > in the same
> > > >way that they are to a Servlet (after all your JSP are 
> compiled into
> > > >Servlets by the server). There's a HttpServletRequest 
> object named
> > > >'request' accesible in your JSP code through which you can
> > > extract the
> > > >values of every parameter and INPUT field of the FORM
> > > submitted by the
> > > >user. Check the Java API for the HttpServletRequest class.
> > > >
> > > >Jerry Thomas wrote:
> > > > >
> > > > > How do I extract data from a FORM and assign the data to
> > > a Java variable
> > > > > that I have declared on my JSP?
> > > > >
> > > > > > >
> > > > > > > I have data contained in a JavaScript variable that
> > > would like to
> > > >pass
> > > > > >to a
> > > > > > > method on my Java bean. I have been successful
> > > retrieving data from
> > > >my
> > > > > >bean
> > > > > > > into my JSP but I cannot figure out how to format the
> > > script so that
> > > >I
> > > > > >can
> > > > > > > send data back to my bean through its methods.
> > > > >
> > > > > >You can pass parameters as FORM hidden fields that can
> > > be extracted
> > > >from
> > > > > >a
> > > > > >servlet and finally passed through to the Bean. This is
> > > independent
> > > >from
> > > > > >the cookie policy set at the browser.
> > > > > >
> > > > > >Juan Alvarez Ferrando
> > > > > >
> 
> ______________________________________________________
> Get Your Private, Free Email at http://www.hotmail.com
> 
> 
> --------------------------------------------------------------
> ------------
> To unsubscribe, email: tomcat-user-unsubscribe@jakarta.apache.org
> For additional commmands, email: tomcat-user-help@jakarta.apache.org
> 

Mime
View raw message