JSP form data retrieval

S

Stuart Palmer

Hi there,
Can anyone tell me if it is possible to get data submitted via a form and
retrieve it on the back end with JSP, without the use of a bean?

If so, would it be possible for someone to supply me a sample section of
code to do this on a web page.

Many thanks

Stu
 
R

Ryan Stewart

Stuart Palmer said:
Hi there,
Can anyone tell me if it is possible to get data submitted via a form and
retrieve it on the back end with JSP, without the use of a bean?

If so, would it be possible for someone to supply me a sample section of
code to do this on a web page.

Many thanks

Stu

<form action="someJSP.jsp">
<input type="text" name="someName" />
<input type="submit" />
</form>

And in the JSP:

<%
String myParameter = request.getParameter("someName");
out.println(myParameter);
%>

Try the JSP tutorial:
http://java.sun.com/products/jsp/html/jspbasics.fm.html
 
K

kaeli

Hi there,
Can anyone tell me if it is possible to get data submitted via a form and
retrieve it on the back end with JSP, without the use of a bean?

Of course.

Make an html page with a form. Have the form's action go to the JSP.
Method is not important for the retrieval of the form value. In the JSP,
just use request.getParameter("paramName").
I have an entire JSP app that doesn't use any beans.

Here's excerpts from my login pages.

from login.jsp
-------------------

<form name="loginFrm" id="loginFrm"
action="checkLogin.jsp" method="get">
<table width="70%">
<tr>
<td>User Name:</td>
<td>
<input type="text"
name="userName" id="userName">
</td>
<td>&nbsp;</td>
</tr>
<tr>
<td>Password:</td>
<td>
<input type="password"
name="psswd" id="psswd">
</td>
<td>&nbsp;<a
href="userMailPsswd.jsp"> <span class="example">(Forgot
your password? Click here.)
</span></a></td>
</tr>
<tr>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
</tr>
<tr>
<td>&nbsp;</td>
<td>
<input type="submit"
value="Submit" id="submit" name="submit">
</td>
<td>&nbsp;</td>
</tr>
</table>
</form>

----------
from checkLogin.jsp
<%
// validate user name and password
String uname =
request.getParameter("userName");
String psswd =
request.getParameter("psswd");
if (uname == null) throw new
IllegalArgumentException("User Name can't be null.");
if (psswd == null) throw new
IllegalArgumentException("Password can't be null.");
if (! userPerms.checkLogin(uname, psswd))
throw new IllegalAccessException("The user name or
password you entered was incorrect. Please try again.");


--
 
B

Berlin Brown

Stuart said:
Hi there,
Can anyone tell me if it is possible to get data submitted via a form and
retrieve it on the back end with JSP, without the use of a bean?

If so, would it be possible for someone to supply me a sample section of
code to do this on a web page.

Many thanks

Stu

I hope you are not talking about doPost() { request.getParameter(); }

Whatever J2EE server(tomcat,WebLogic,jboss) you installed will have a
myriad of samples. For examples go to your
http://localhost:8080/index.jsp(tomcat)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,432
Messages
2,571,680
Members
48,796
Latest member
Greg L.

Latest Threads

Top