Win a copy of TDD for a Shopping Website LiveProject this week in the Testing forum!
  • 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
  • Paul Clapham
  • Ron McLeod
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Frits Walraven
Bartenders:
  • Piet Souris
  • Himai Minh

request.parameter

 
Ranch Hand
Posts: 136
Android Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 .
 
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 136
Android Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 136
Android Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 41
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 136
Android Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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!!!
 
Ranch Hand
Posts: 2874
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
The only taste of success some people get is to take a bite out of you. Or this tiny ad:
Free, earth friendly heat - from the CodeRanch trailboss
https://www.kickstarter.com/projects/paulwheaton/free-heat
reply
    Bookmark Topic Watch Topic
  • New Topic