aspose file tools*
The moose likes JSP and the fly likes request.parameter Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "request.parameter" Watch "request.parameter" New topic
Author

request.parameter

Aris Doxakis
Ranch Hand

Joined: Dec 05, 2004
Posts: 136

I have a page Registration.jsp and i want to pass some data from fields to a validation.jsp page.I see that the data pass to the other page ,but
i can't use them at a sql statement.

for example,

Insert into(one,two,three) values (request.parameter("one"),.....)

this doesn't work.the sql statement doesn't take the values .
Itapaj� Takeguma
Ranch Hand

Joined: Jul 21, 2004
Posts: 41
If you want to pass a PARAMETER to the second jsp, you can just do:

<jsp:include page='second.jsp' >
<param name='param1' value='value1' />
</jsp:include>

if you're using <%@ include %> than you shall try to use the page variable or even a request and set an ATTRIBUTE.

Hope I could help,
Itapaj� Takeguma
Aris Doxakis
Ranch Hand

Joined: Dec 05, 2004
Posts: 136

I'm sending the two jsp pages.

first page

<%@ page import="java.util.Date, java.sql.*, java.util.*" %>
<%@ page contentType="text/html; charset=iso-8859-7" %>

<html>
<head>
<title>New User -- Registration</title>
</head>
<body>

<Table width="140%">

<TR>
<TD> <img src="/images/logo.JPG" width="217" height="117"> </TD>
</Table>

<hr align="center" width="100%" size="7" noshade color="Red">

<Form method="post" name="form" action = "Validation.jsp">
<H3 align="center" color="red">Please Fill All Fields With * Besides Them </H3>
<Table width="20%">
<TR> <TD>Όνομα</TD> <TD> <input type="text" name="FName" size="20"> </TD> <TD>*</TD> </TR>
<TR> <TD>Επώνυμο</TD> <TD> <input type="text" name="LName" size="20"> </TD> <TD>*</TD> </TR>
<TR> <TD>Διεύθυνση</TD> <TD> <input type="text" name="Address" size="20"> </TD> <TD>*</TD> </TR>
<TR> <TD>Χώρα</TD> <TD> <input type="text" name="Country" size="20"> </TD> <TD>*</TD> </TR>
<TR> <TD>Περιοχή</TD> <TD> <input type="text" name="City" size="20"> </TD> </TR>
<TR> <TD>Τηλέφωνο</TD> <TD> <input type="text" name="Telephone" size="20"> </TD> <TD>*</TD> </TR>
<TR> <TD>E-Mail</TD> <TD> <input type="text" name="e_mail" size="20"> </TD> <TD>*</TD> </TR>
<TR>
<TD> <input type="Submit" name="Submit" value="Submit"> </TD>
<TD> <input type="Reset" name="Clear" value="Clear"> </TD>
</TR>
</Table>
</Form>
</Body>
</HTML>

second page


<%@ page import="java.util.Date, java.sql.*, java.util.*" %>
<%@ page contentType="text/html; charset=iso-8859-7" %>

<html>
<head>
<title>New User -- Validation</title>
</head>
<body>

<%
String FName = request.getParameter("FName");
String LName = request.getParameter("LName");
String Address = request.getParameter("Address");
String Country = request.getParameter("Country");
String City = request.getParameter("City");
String Telephone = request.getParameter("Telephone");
String e_mail = request.getParameter("e_mail");

Class.forName("org.gjt.mm.mysql.Driver");
Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/e_store");

Statement stmt = con.createStatement();
ResultSet rs = stmt.executeQuery("SELECT @max_CuID := MAX(Customer_ID) FROM Customers;");
String flag;

if ((FName == " ") | (LName == " ") | (Address == " ") | (Country == " ") | (Telephone == " ") | (e_mail == " "))
flag = "f";
else
flag = "t";

while (rs.next())
{
String m = rs.getString(1);
}
if (flag == "f")
response.sendRedirect("NSuccess.jsp");
else
{
stmt.executeUpdate("Insert into Customers (Customer_ID,FName,LName,Address,Country,City,Telephone,e_mail) " +
"Values('m +1',FName,LName,Address,Country,
City,Telephone,'he_mail');");
stmt.close();
con.close();
response.sendRedirect("Success.jsp");
}
rs.close();
stmt.close();
%>
</Body>
</HTML>

The parameters take the values but the sql statement doesn't.Maybe i am doing something wrong.

Aris Doxakis
Ranch Hand

Joined: Dec 05, 2004
Posts: 136

I forgot the basic.

iwant to use the values from the fields in page one so i can use them in page two in an insert statement.the insert statement doesn't find any values in the variables.i need some help..thx....!!!
Itapaj� Takeguma
Ranch Hand

Joined: Jul 21, 2004
Posts: 41
it seems wrong to me your statement u're using "select .... VALUES (val1, val2...)" where you should use "selec ... VALUES (" + val1 + ", '" + val2 + "' ...)"

instead you could see preparedStatement.

You could try to put the second jsp page inside a servlet, so you could debug.

hope I could help you,
Itapaj� Takeguma.
Aris Doxakis
Ranch Hand

Joined: Dec 05, 2004
Posts: 136

The select sql statement works allright.

the insert sql statement doesn't work propoerly.

the second jsp page gets the values form the first.

But when i use them in the insert sql statement they are empty.

Any suggestions will help much!!!
Adeel Ansari
Ranch Hand

Joined: Aug 15, 2004
Posts: 2874
sql statement inside jsp is considered as a sin.
if prototyping use jstl sql tags instead.
and offcourse it is not the answer just a suggestion.

cheers.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: request.parameter