Jasbir21
asked on
Whre to put <a href ...>
This is jsp code for vol2.jsp
<%@ page import="java.sql.*, com.dhal.*"%>
<jsp:useBean id="vol" class="com.dhal.volun" scope="session"/>
<jsp:setProperty name="vol" property="*"/>
<Html>
<body>
<form action="vol.jsp...>
......
<% database queries.....%>
<input type="submit" value="Update">
</form>
When the user presses the update, it needs to go to vol.jsp
where do i put
<a href= ? >so that it would go to vol.jsp
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Errr...yes....that's fine...
What's wrong with it? vol2 will post the form to vol
Then in vol, you can get the values out with:
request.getParameter( "username" ) ;
etc
What's wrong with it? vol2 will post the form to vol
Then in vol, you can get the values out with:
request.getParameter( "username" ) ;
etc
ASKER
Tim,
I got one more question to ask,
i don't know what's wrong with this statement:
String y="update accou set " +"password='"+passwd+"'," + "verifypassdword='" +verify+"' " +
"where username='"+username+"'";
Thanks
I got one more question to ask,
i don't know what's wrong with this statement:
String y="update accou set " +"password='"+passwd+"'," + "verifypassdword='" +verify+"' " +
"where username='"+username+"'";
Thanks
ASKER
I get it , put the action in the form , i thought you meant post the vol codes.
Could you pls look at the sql statement, really don't know what's wrong
Thanks
Could you pls look at the sql statement, really don't know what's wrong
Thanks
Should be ok, so long as the username or password doesn't include ' chars
Have you considered PreparedStatements?
Much easier for this sort of thing...
And the string looks nicer like:
String y = "update accou set password='" + passwd + "', verifypassdword='" +verify+ "' where username='" + username + "'" ;
Have you considered PreparedStatements?
Much easier for this sort of thing...
And the string looks nicer like:
String y = "update accou set password='" + passwd + "', verifypassdword='" +verify+ "' where username='" + username + "'" ;
Change:
try
{
passwd=vol.getPasswd();
verify=vol.getVerifypwd();
Class.forName("com.mysql.j dbc.Driver ").newInst ance();
connection = DriverManager.getConnectio n(connecti onURL, "", "");
String y="update accou set " +"password='"+passwd+"'," + "verifypassdword='" +verify+"' " +
"where username='"+username+"'";
prep1=connection.prepareSt atement(y) ;
prep1.executeUpdate();
S
}
to:
try
{
passwd=vol.getPasswd();
verify=vol.getVerifypwd();
Class.forName("com.mysql.j dbc.Driver ").newInst ance();
connection = DriverManager.getConnectio n(connecti onURL, "", "");
String y = "update accou set password=?, verifypassdword=? where username=?" ;
prep1=connection.prepareSt atement( y );
prep1.setString( 1, passwd ) ;
prep1.setString( 2, verify ) ;
prep1.setString( 3, username ) ;
prep1.executeUpdate();
}
try
{
passwd=vol.getPasswd();
verify=vol.getVerifypwd();
Class.forName("com.mysql.j
connection = DriverManager.getConnectio
String y="update accou set " +"password='"+passwd+"'," + "verifypassdword='" +verify+"' " +
"where username='"+username+"'";
prep1=connection.prepareSt
prep1.executeUpdate();
S
}
to:
try
{
passwd=vol.getPasswd();
verify=vol.getVerifypwd();
Class.forName("com.mysql.j
connection = DriverManager.getConnectio
String y = "update accou set password=?, verifypassdword=? where username=?" ;
prep1=connection.prepareSt
prep1.setString( 1, passwd ) ;
prep1.setString( 2, verify ) ;
prep1.setString( 3, username ) ;
prep1.executeUpdate();
}
ASKER
Hi,
I guess i did something wrong, i didn't get any errors but the data is not updating..
I guess i did something wrong, i didn't get any errors but the data is not updating..
Any stack traces being output in the log files?
ASKER
Surprisingly no,
it is as if the code the understand which user i am pointing to
it is as if the code the understand which user i am pointing to
can you post your updating code?
(vol.jsp)?
(vol.jsp)?
ASKER
I tried something, i changed:
<form action="vol.jsp">
to
<form action="vol2.jsp">
meaning that after pressing the submit , i call the same page back and not vol.jsp,suprisingly it gets updated,
but then how do i call vol.jsp
user would use vol2.jsp to input data
the vol.jsp code just shows the data inputed:
<%@ page import="java.sql.*"%>
<Html>
<body>
<%
String connectionURL = "jdbc:mysql://localhost:33 06/mydatab ase?user=; password=" ;
Connection connection = null;
PreparedStatement prep1;
prep1=null;
ResultSet rs=null;
ResultSet rs1=null;
Statement statement=null;
String username=null;
String passwd=null;
String verify=null;
String name=null;
String education=null;
String city=null;
String state=null;
String post=null;
String qualify=null;
String house1=null;
String house2=null;
String office1=null;
String office2=null;
String mobile1=null;
String mobile2=null;
String email=null;
String notify=null;
String add1=null;
String add2=null;
Statement statement1=null;
try
{
Class.forName("com.mysql.j dbc.Driver ").newInst ance();
connection = DriverManager.getConnectio n(connecti onURL, "", "");
statement=connection.creat eStatement ();
String myquery="select * from accou where username='jasbir22'";
rs=statement.executeQuery( myquery);
boolean anyRecords=rs.next();
String query="select * from my where username='jasbir22'";
statement1=connection.crea teStatemen t();
rs1=statement1.executeQuer y(query);
boolean any=rs1.next();
if(rs1.getString(1).trim() .equals(rs .getString (1).trim() ))
{
name=rs1.getString(2).trim ();
education=rs1.getString(3) .trim();
city=rs1.getString(4).trim ();
state=rs1.getString(5).tri m();
post=rs1.getString(6).trim ();
qualify=rs1.getString(7).t rim();
house1=rs1.getString(8).tr im();
house2=rs1.getString(9).tr im();
office1=rs1.getString(10). trim();
office2=rs1.getString(11). trim();
mobile1=rs1.getString(12). trim();
mobile2=rs1.getString(13). trim();
email=rs1.getString(14).tr im();
notify=rs1.getString(15).t rim();
add1=rs1.getString(16).tri m();
add2=rs1.getString(17).tri m();
username=rs.getString(1).t rim();
passwd=rs.getString(2).tri m();
System.out.println(passwd) ;
verify=rs.getString(3).tri m();
}
}
catch(SQLException ex )
{
ex.printStackTrace() ;
}
catch( ClassNotFoundException ex )
{
ex.printStackTrace() ;
}
finally
{
try { if( rs != null ) rs.close() ; } catch( Exception ex ) {ex.printStackTrace() ;}
try { if( prep1 != null ) prep1.close() ; } catch( Exception ex ) {ex.printStackTrace() ;}
try { if( rs1 != null ) rs1.close() ; } catch( Exception ex ) {ex.printStackTrace() ;}
try { if( connection != null ) connection.close() ; } catch( Exception ex ) {ex.printStackTrace() ;}
}
%>
Username : <%=username%><p/>
Password : <%=passwd%><p/>
Verify Password : <%=verify%>
<p/>
Name : <%=name%><p/>
Education : <%=education%></p>
City : <%=city%></p>
State : <%=state%></p>
Qualification : <%=qualify%></p>
Phone (H) : <%=house1%> <%= house2%></ p>
Phone (O) : <%=office1%> <% =office2%> </p>
Handphone : <%=mobile1%> <% =mobile2%> </p>
Email :<%=email%></p>
Notification :<%=notify%></p>
Address : <%=add1%></p>
<%=add2%>
</Body>
</html>
<form action="vol.jsp">
to
<form action="vol2.jsp">
meaning that after pressing the submit , i call the same page back and not vol.jsp,suprisingly it gets updated,
but then how do i call vol.jsp
user would use vol2.jsp to input data
the vol.jsp code just shows the data inputed:
<%@ page import="java.sql.*"%>
<Html>
<body>
<%
String connectionURL = "jdbc:mysql://localhost:33
Connection connection = null;
PreparedStatement prep1;
prep1=null;
ResultSet rs=null;
ResultSet rs1=null;
Statement statement=null;
String username=null;
String passwd=null;
String verify=null;
String name=null;
String education=null;
String city=null;
String state=null;
String post=null;
String qualify=null;
String house1=null;
String house2=null;
String office1=null;
String office2=null;
String mobile1=null;
String mobile2=null;
String email=null;
String notify=null;
String add1=null;
String add2=null;
Statement statement1=null;
try
{
Class.forName("com.mysql.j
connection = DriverManager.getConnectio
statement=connection.creat
String myquery="select * from accou where username='jasbir22'";
rs=statement.executeQuery(
boolean anyRecords=rs.next();
String query="select * from my where username='jasbir22'";
statement1=connection.crea
rs1=statement1.executeQuer
boolean any=rs1.next();
if(rs1.getString(1).trim()
{
name=rs1.getString(2).trim
education=rs1.getString(3)
city=rs1.getString(4).trim
state=rs1.getString(5).tri
post=rs1.getString(6).trim
qualify=rs1.getString(7).t
house1=rs1.getString(8).tr
house2=rs1.getString(9).tr
office1=rs1.getString(10).
office2=rs1.getString(11).
mobile1=rs1.getString(12).
mobile2=rs1.getString(13).
email=rs1.getString(14).tr
notify=rs1.getString(15).t
add1=rs1.getString(16).tri
add2=rs1.getString(17).tri
username=rs.getString(1).t
passwd=rs.getString(2).tri
System.out.println(passwd)
verify=rs.getString(3).tri
}
}
catch(SQLException ex )
{
ex.printStackTrace() ;
}
catch( ClassNotFoundException ex )
{
ex.printStackTrace() ;
}
finally
{
try { if( rs != null ) rs.close() ; } catch( Exception ex ) {ex.printStackTrace() ;}
try { if( prep1 != null ) prep1.close() ; } catch( Exception ex ) {ex.printStackTrace() ;}
try { if( rs1 != null ) rs1.close() ; } catch( Exception ex ) {ex.printStackTrace() ;}
try { if( connection != null ) connection.close() ; } catch( Exception ex ) {ex.printStackTrace() ;}
}
%>
Username : <%=username%><p/>
Password : <%=passwd%><p/>
Verify Password : <%=verify%>
<p/>
Name : <%=name%><p/>
Education : <%=education%></p>
City : <%=city%></p>
State : <%=state%></p>
Qualification : <%=qualify%></p>
Phone (H) : <%=house1%> <%=
Phone (O) : <%=office1%> <%
Handphone : <%=mobile1%> <%
Email :<%=email%></p>
Notification :<%=notify%></p>
Address : <%=add1%></p>
<%=add2%>
</Body>
</html>
oh...
vol doesn't do any updating in it... you do the update in vol2...
I would add a bit to vol2
get the form to post to vol2
and after you do the update, do:
response.sendRedirect( "vol.jsp" ) ;
vol doesn't do any updating in it... you do the update in vol2...
I would add a bit to vol2
get the form to post to vol2
and after you do the update, do:
response.sendRedirect( "vol.jsp" ) ;
ASKER
Hi,
When i put the line, it automatically redirects to vol.jsp.
But I need to redirect it only after, the user presses the submit button because, then only i can enter the changes(update S) and then press submit,
Thanks
When i put the line, it automatically redirects to vol.jsp.
But I need to redirect it only after, the user presses the submit button because, then only i can enter the changes(update S) and then press submit,
Thanks
put a hidden value into the form:
<form action="vol2.jsp">
<input type="hidden" name="posted" value="yes">
...rest of your form...
</form>
then, only redirect (and do the update) if this value exists;
if( request.getParameter( "posted" ) != null )
{
// form was posted!! Not just a click!!
<form action="vol2.jsp">
<input type="hidden" name="posted" value="yes">
...rest of your form...
</form>
then, only redirect (and do the update) if this value exists;
if( request.getParameter( "posted" ) != null )
{
// form was posted!! Not just a click!!
ASKER
Wow,it s working, thanks so much,
I would learn more on hidden type,it is very interesting .
Thanks again
I would learn more on hidden type,it is very interesting .
Thanks again
ASKER
<%@ page import="java.sql.*, com.dhal.*"%>
<jsp:useBean id="vol" class="com.dhal.volun" scope="session"/>
<jsp:setProperty name="vol" property="*"/>
<Html>
<body>
<%
String connectionURL = "jdbc:mysql://localhost:33
Connection connection = null;
ResultSet rs=null;
ResultSet rs1=null;
Statement statement=null;
String username=null;
String passwd=null;
String verify=null;
String name=null;
String education=null;
String city=null;
String state=null;
String post=null;
String qualify=null;
String house1=null;
String house2=null;
String office1=null;
String office2=null;
String mobile1=null;
String mobile2=null;
String email=null;
String notify=null;
String add1=null;
String add2=null;
Statement statement1=null;
try
{
Class.forName("com.mysql.j
connection = DriverManager.getConnectio
statement=connection.creat
String myquery="select * from accou where username='jasbir22'";
rs=statement.executeQuery(
boolean anyRecords=rs.next();
String query="select * from my where username='jasbir22'";
statement1=connection.crea
rs1=statement1.executeQuer
boolean any=rs1.next();
if(rs1.getString(1).trim()
{
name=rs1.getString(2).trim
education=rs1.getString(3)
city=rs1.getString(4).trim
state=rs1.getString(5).tri
post=rs1.getString(6).trim
qualify=rs1.getString(7).t
house1=rs1.getString(8).tr
house2=rs1.getString(9).tr
office1=rs1.getString(10).
office2=rs1.getString(11).
mobile1=rs1.getString(12).
mobile2=rs1.getString(13).
email=rs1.getString(14).tr
notify=rs1.getString(15).t
add1=rs1.getString(16).tri
add2=rs1.getString(17).tri
username=rs.getString(1).t
passwd=rs.getString(2).tri
verify=rs.getString(3).tri
}
}
catch(SQLException ex )
{
ex.printStackTrace() ;
}
catch( ClassNotFoundException ex )
{
ex.printStackTrace() ;
}
finally
{
try { if( rs != null ) rs.close() ; } catch( Exception ex ) {ex.printStackTrace() ;}
// try { if( prep1 != null ) prep1.close() ; } catch( Exception ex ) {ex.printStackTrace() ;}
try { if( rs1 != null ) rs1.close() ; } catch( Exception ex ) {ex.printStackTrace() ;}
try { if( connection != null ) connection.close() ; } catch( Exception ex ) {ex.printStackTrace() ;}
}
%>
<%
//String connectionURL = "jdbc:mysql://localhost:33
//Connection connection = null;
PreparedStatement prep1=null;
try
{
passwd=vol.getPasswd();
verify=vol.getVerifypwd();
Class.forName("com.mysql.j
connection = DriverManager.getConnectio
String y="update accou set " +"password='"+passwd+"'," + "verifypassdword='" +verify+"' " +
"where username='"+username+"'";
prep1=connection.prepareSt
prep1.executeUpdate();
S
}
catch(SQLException ex )
{
ex.printStackTrace() ;
}
catch( ClassNotFoundException ex )
{
ex.printStackTrace() ;
}
finally
{
//try { if( rs != null ) rs.close() ; } catch( Exception ex ) {ex.printStackTrace() ;}
try { if( prep1 != null ) prep1.close() ; } catch( Exception ex ) {ex.printStackTrace() ;}
//try { if( rs1 != null ) rs1.close() ; } catch( Exception ex ) {ex.printStackTrace() ;}
try { if( connection != null ) connection.close() ; } catch( Exception ex ) {ex.printStackTrace() ;}
}
%>
<table border="4" BGColor="#FFF8DC" width="100%">
<tr>
<td>
<Font Color="#000000" Face="Garamond" Size="4">
<b>ACCOUNT INFORMATION</b>
</Font>
</td>
</tr>
</table>
<br>
<form action="vol2.jsp" method="post">
<Font Size="4 Color="Black" Face="Garamond" Align="Center">
<br>
Username :
<input type="text" name="username" value=<%=username%> size=20 /><br>
Password :
<input type="password" name="passwd" value=<%=passwd%> size=20/><br>
Verify Password :
<input type="password" name="verifypwd" value=<%=verify%> size=20/> <br>
<input type="submit" value="Submit">
</form>
</Font>
</body>
<html>
The vol.jsp<%@ page import="java.sql.*"%>
<Html>
<body>
<%
String connectionURL = "jdbc:mysql://localhost:33
Connection connection = null;
PreparedStatement prep1;
prep1=null;
ResultSet rs=null;
ResultSet rs1=null;
Statement statement=null;
String username=null;
String passwd=null;
String verify=null;
String name=null;
String education=null;
String city=null;
String state=null;
String post=null;
String qualify=null;
String house1=null;
String house2=null;
String office1=null;
String office2=null;
String mobile1=null;
String mobile2=null;
String email=null;
String notify=null;
String add1=null;
String add2=null;
Statement statement1=null;
try
{
Class.forName("com.mysql.j
connection = DriverManager.getConnectio
statement=connection.creat
String myquery="select * from accou where username='jasbir22'";
rs=statement.executeQuery(
boolean anyRecords=rs.next();
String query="select * from my where username='jasbir22'";
statement1=connection.crea
rs1=statement1.executeQuer
boolean any=rs1.next();
if(rs1.getString(1).trim()
{
name=rs1.getString(2).trim
education=rs1.getString(3)
city=rs1.getString(4).trim
state=rs1.getString(5).tri
post=rs1.getString(6).trim
qualify=rs1.getString(7).t
house1=rs1.getString(8).tr
house2=rs1.getString(9).tr
office1=rs1.getString(10).
office2=rs1.getString(11).
mobile1=rs1.getString(12).
mobile2=rs1.getString(13).
email=rs1.getString(14).tr
notify=rs1.getString(15).t
add1=rs1.getString(16).tri
add2=rs1.getString(17).tri
username=rs.getString(1).t
passwd=rs.getString(2).tri
System.out.println(passwd)
verify=rs.getString(3).tri
}
}
catch(SQLException ex )
{
ex.printStackTrace() ;
}
catch( ClassNotFoundException ex )
{
ex.printStackTrace() ;
}
finally
{
try { if( rs != null ) rs.close() ; } catch( Exception ex ) {ex.printStackTrace() ;}
try { if( prep1 != null ) prep1.close() ; } catch( Exception ex ) {ex.printStackTrace() ;}
try { if( rs1 != null ) rs1.close() ; } catch( Exception ex ) {ex.printStackTrace() ;}
try { if( connection != null ) connection.close() ; } catch( Exception ex ) {ex.printStackTrace() ;}
}
%>
Username : <%=username%><p/>
Password : <%=passwd%><p/>
Verify Password : <%=verify%>
<p/>
Name : <%=name%><p/>
Education : <%=education%></p>
City : <%=city%></p>
State : <%=state%></p>
Qualification : <%=qualify%></p>
Phone (H) : <%=house1%> <%=
Phone (O) : <%=office1%> <%
Handphone : <%=mobile1%> <%
Email :<%=email%></p>
Notification :<%=notify%></p>
Address : <%=add1%></p>
<%=add2%>
</Body>
</html>
Thanks