0

Hi all,
i did code in jsp for "change password" when user want to change his password he have to enter his old password and then new password.
if he enter wrong password there will be error msg display "sorry you have entered wrong password, and if he enter correct password msg will display "your password has successfully change", this is the code:

<%@ page contentType="text/html; charset=iso-8859-1" language="java" import="java.sql.*" errorPage="" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"[URL]http://www.w3.org/TR/html4/loose.dtd[/URL]">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Untitled Document</title>
<style type="text/css">
<!--
.style1 {font-size: 16px;
 font-weight: bold;
 font-family: Verdana, Arial, Helvetica, sans-serif;
}
.style15 {font-family: "Cooper Black"}
.style16 {font-size: 12px; font-weight: bold; }
.style3 {font-size: 18px}
-->
</style>
</head>
<body>

<table width="700" height="735" border="0" align="center" cellpadding="0" cellspacing="0" id="Table_01">
  <tr>
    <td height="132" colspan="4"><img src="images/simple_01.gif" width="700" height="132" alt=""></td>
  </tr>
  <tr>
    <td height="51" colspan="4"><img src="images/simple_02.gif" width="700" height="51" alt=""></td>
  </tr>
  <tr>
    <td height="233" colspan="2" background="images/simple_03.gif"><table width="185" border="0" align="center">
        <tr>
          <td><form name="form1" method="post" action="LogInPage.jsp">
              <table width="189" height="177" border="0" align="center">
                <tr>
                  <td><div align="right"></div>
                      <div align="right"><span class="style1">Log In</span></div></td>
                  <td>&nbsp;</td>
                </tr>
                <tr>
                  <td width="100"><div align="right"><span class="style16">User Name:</span></div></td>
                  <td width="90" align="right"><div align="left">
                      <input name="txtUserName" type="text" id="txtUserName" size="10">
                  </div></td>
                </tr>
                <tr>
                  <td><div align="right"><span class="style16">Password:</span></div></td>
                  <td><input name="txtPass" type="password" id="txtPass" size="10"></td>
                </tr>
                <tr>
                  <td colspan="2"><div align="right">
                      <input type="submit" name="Submit" value="Log In">
                      <input type="reset" name="Reset" value="Reset">
                  </div></td>
                </tr>
                <tr>
                  <td height="43" colspan="2"><div align="center"><a href="ChangePassword.htm">ChangePassword</a></div></td>
                </tr>
              </table>
          </form></td>
        </tr>
    </table></td>
    <td rowspan="2" background="images/simple_04.gif"><table width="445" border="0">
        <tr>
          <td width="439"><div align="center">
              <p>

              <p>
            <%

   Connection conn;
   Statement stm = null;
            String r = "";
            ResultSet rs = null;

            String user=request.getParameter("txtUser");
      String pass=request.getParameter("txtOldPass");
      String newpass=request.getParameter("txtNewPass");


            r = "update PersonalInfo set Password1 ='" + newpass + "' where UserName = '" + user + "' and Password1 = '" + pass+ "'";

            try
            {
            sqlStat="SELECT * from PersonalInfo where UserName='" +user+ "' and Password1='" +pass+ "'";
            out.print(sqlStat);
            Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
            Connection con = DriverManager.getConnection("jdbc:odbc:liwa");
              //  rs.next();
            stm = con.createStatement();
            stm.executeUpdate(r);
            rs = stmt.executeQuery(sqlStat);

            if (!rs.next())
            {
            out.println("you have entered wrong password");
            out.println("<a href=ChangePassword.htm>Click here to try again</a>");
            }
            else
            {
            out.println("Password Changed Successfully<br/>"); 
            out.print("<a href='Admin.htm'> Home </a>");

           }
           }

           rs.close();
           conn.close();
             catch (Exception e){
              out.println("There is an error" + e.getMessage());
           }
%>
              </p>
              <p>&nbsp; </p>
          </div></td>
        </tr>
        <tr>
          <td><div align="justify"><span class="style15"></span></div></td>
        </tr>
    </table></td>
    <td rowspan="3" background="images/simple_05.gif">&nbsp;</td>
  </tr>
  <tr>
    <td height="298" colspan="2" background="images/simple_06.gif"><table width="200" border="0" align="center">
        <tr>
          <td><form name="form2" method="post" action="">
              <table width="200" height="245" border="0" align="center">
                <tr>
                  <td width="122"><div align="right"><span class="style1">Reservation </span></div></td>
                  <td width="68" height="36">&nbsp;</td>
                </tr>
                <tr>
                  <td><div align="right"><span class="style16">Check In Date:</span></div></td>
                  <td height="21">&nbsp;</td>
                </tr>
                <tr>
                  <td colspan="2"><div align="center"><span class="style3">
                      <select name="select" size="1">
                        <option>1</option>
                        <option>2</option>
                        <option>3</option>
                        <option>4</option>
                        <option>5</option>
                        <option>6</option>
                        <option>7</option>
                        <option>8</option>
                        <option>9</option>
                        <option>10</option>
                        <option>11</option>
                        <option>12</option>
                        <option>13</option>
                        <option>14</option>
                        <option>15</option>
                        <option>16</option>
                        <option>17</option>
                        <option>18</option>
                        <option>19</option>
                        <option>20</option>
                        <option>21</option>
                        <option>22</option>
                        <option>23</option>
                        <option>24</option>
                        <option>25</option>
                        <option>26</option>
                        <option>27</option>
                        <option>28</option>
                        <option>29</option>
                        <option>30</option>
                        <option>31</option>
                      </select>
                      <select name="select" size="1">
                        <option>1</option>
                        <option>2</option>
                        <option>3</option>
                        <option>4</option>
                        <option>5</option>
                        <option>6</option>
                        <option>7</option>
                        <option>8</option>
                        <option>9</option>
                        <option>10</option>
                        <option>11</option>
                        <option>12</option>
                      </select>
                      <select name="select" size="1">
                        <option>2007</option>
                        <option>2008</option>
                        <option>2009</option>
                        <option>2010</option>
                      </select>
                  </span><span class="style3"> </span></div></td>
                </tr>
                <tr>
                  <td><div align="right"><span class="style16">Check Out Date:</span></div></td>
                  <td>&nbsp;</td>
                </tr>
                <tr>
                  <td colspan="2"><div align="center"><span class="style3">
                      <select name="select" size="1">
                        <option>1</option>
                        <option>2</option>
                        <option>3</option>
                        <option>4</option>
                        <option>5</option>
                        <option>6</option>
                        <option>7</option>
                        <option>8</option>
                        <option>9</option>
                        <option>10</option>
                        <option>11</option>
                        <option>12</option>
                        <option>13</option>
                        <option>14</option>
                        <option>15</option>
                        <option>16</option>
                        <option>17</option>
                        <option>18</option>
                        <option>19</option>
                        <option>20</option>
                        <option>21</option>
                        <option>22</option>
                        <option>23</option>
                        <option>24</option>
                        <option>25</option>
                        <option>26</option>
                        <option>27</option>
                        <option>28</option>
                        <option>29</option>
                        <option>30</option>
                        <option>31</option>
                      </select>
                      <select name="select" size="1">
                        <option>1</option>
                        <option>2</option>
                        <option>3</option>
                        <option>4</option>
                        <option>5</option>
                        <option>6</option>
                        <option>7</option>
                        <option>8</option>
                        <option>9</option>
                        <option>10</option>
                        <option>11</option>
                        <option>12</option>
                      </select>
                      <select name="select" size="1">
                        <option>2007</option>
                        <option>2008</option>
                        <option>2009</option>
                        <option>2010</option>
                      </select>
                  </span></div></td>
                </tr>
                <tr>
                  <td><div align="right"><span class="style16">Room Type:</span></div></td>
                  <td>&nbsp;</td>
                </tr>
                <tr>
                  <td colspan="2" valign="bottom"><div align="center"><span class="style3">
                      <select name="select" size="1">
                        <option value="King">King</option>
                        <option value="Big Double">Big Double</option>
                        <option value="Small Double">Small Double</option>
                        <option value="Double">Double</option>
                      </select>
                  </span></div></td>
                </tr>
                <tr>
                  <td height="35" colspan="2"><div align="center"><span class="style3">
                      <input type="submit" name="Submit" value="Check Availibility">
                  </span></div></td>
                </tr>
              </table>
          </form></td>
        </tr>
    </table></td>
  </tr>
  <tr>
    <td background="images/simple_07.gif">&nbsp;</td>
    <td colspan="2" background="images/simple_08.gif">&nbsp;</td>
  </tr>
  <tr>
    <td><img src="images/spacer.gif" width="13" height="1" alt=""></td>
    <td><img src="images/spacer.gif" width="194" height="1" alt=""></td>
    <td><img src="images/spacer.gif" width="468" height="1" alt=""></td>
    <td><img src="images/spacer.gif" width="25" height="1" alt=""></td>
  </tr>
</table>
</body>
</html>

but this code doesnt display right, this error display:

An error occurred at line: 70 in the jsp file: /saroo/site/ChangePassAction.jsp
Generated servlet error:
Syntax error, insert "Finally" to complete TryStatement

An error occurred at line: 70 in the jsp file: /saroo/site/ChangePassAction.jsp
Generated servlet error:
Syntax error, insert "}" to complete Block

Generated servlet error:
Syntax error on tokens, delete these tokens

Generated servlet error:
Syntax error on token "finally", delete this token

plllllz help :)

Edited by happygeek: fixed formatting

3
Contributors
4
Replies
5
Views
9 Years
Discussion Span
Last Post by suvitha_raj
0

to be easier for you, this is the code that had error:

<%

Connection conn;
Statement stm = null;
            String r = "";
            ResultSet rs = null;

            String user=request.getParameter("txtUser");
      String pass=request.getParameter("txtOldPass");
      String newpass=request.getParameter("txtNewPass");


            r = "update PersonalInfo set Password1 ='" + newpass + "' where UserName = '" + user + "' and Password1 = '" + pass+ "'";

            try
            {
            sqlStat="SELECT * from PersonalInfo where UserName='" +user+ "' and Password1='" +pass+ "'";
            out.print(sqlStat);
            Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
            Connection con = DriverManager.getConnection("jdbc:odbc:liwa");
              //  rs.next();
            stm = con.createStatement();
            stm.executeUpdate(r);
            rs = stmt.executeQuery(sqlStat);

            if (!rs.next())
            {
            out.println("you have entered wrong password");
            out.println("<a href=ChangePassword.htm>Click here to try again</a>");
            }
            else
            {
            out.println("Password Changed Successfully<br/>"); 
            out.print("<a href='Admin.htm'> Home </a>");

           }
           }

           rs.close();
           conn.close();
             catch (Exception e){
              out.println("There is an error" + e.getMessage());
           }
%>

thnx :)

Edited by happygeek: fixed formatting

0

try have to by accomplished by one or more catch blocks to handle exceptions and in addition you can use finaly after either try or catch complished. Learn more about Exception handling at http://java.sun.com/docs/books/tutorial/essential/exceptions/index.html

in your case this should sort problem

catch(SQLException sqlEx)
{
     sqlEx.printStackTrace();
}

Also it is very bad idea to use JSP to access database, you should validate your entry data before submiting in your JSP, then submit them to servlet which will set connection with DB and store them. Plus in servlet you can setup session and store data there so they can be passed from page to page

0

thanks peter_budo for your reply, i solved it, and now its workin probebly, i knew what my mistake is.
thank you for your help :)

Regards,
saasbs

0

Hi all,
i did code in jsp for "change password" when user want to change his password he have to enter his old password and then new password.
if he enter wrong password there will be error msg display "sorry you have entered wrong password, and if he enter correct password msg will display "your password has successfully change", this is the code:

<%@ page contentType="text/html; charset=iso-8859-1" language="java" import="java.sql.*" errorPage="" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"[URL]http://www.w3.org/TR/html4/loose.dtd[/URL]">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Untitled Document</title>
<style type="text/css">
<!--
.style1 {font-size: 16px;
 font-weight: bold;
 font-family: Verdana, Arial, Helvetica, sans-serif;
}
.style15 {font-family: "Cooper Black"}
.style16 {font-size: 12px; font-weight: bold; }
.style3 {font-size: 18px}
-->
</style>
</head>
<body>

<table width="700" height="735" border="0" align="center" cellpadding="0" cellspacing="0" id="Table_01">
  <tr>
    <td height="132" colspan="4"><img src="images/simple_01.gif" width="700" height="132" alt=""></td>
  </tr>
  <tr>
    <td height="51" colspan="4"><img src="images/simple_02.gif" width="700" height="51" alt=""></td>
  </tr>
  <tr>
    <td height="233" colspan="2" background="images/simple_03.gif"><table width="185" border="0" align="center">
        <tr>
          <td><form name="form1" method="post" action="LogInPage.jsp">
              <table width="189" height="177" border="0" align="center">
                <tr>
                  <td><div align="right"></div>
                      <div align="right"><span class="style1">Log In</span></div></td>
                  <td>&nbsp;</td>
                </tr>
                <tr>
                  <td width="100"><div align="right"><span class="style16">User Name:</span></div></td>
                  <td width="90" align="right"><div align="left">
                      <input name="txtUserName" type="text" id="txtUserName" size="10">
                  </div></td>
                </tr>
                <tr>
                  <td><div align="right"><span class="style16">Password:</span></div></td>
                  <td><input name="txtPass" type="password" id="txtPass" size="10"></td>
                </tr>
                <tr>
                  <td colspan="2"><div align="right">
                      <input type="submit" name="Submit" value="Log In">
                      <input type="reset" name="Reset" value="Reset">
                  </div></td>
                </tr>
                <tr>
                  <td height="43" colspan="2"><div align="center"><a href="ChangePassword.htm">ChangePassword</a></div></td>
                </tr>
              </table>
          </form></td>
        </tr>
    </table></td>
    <td rowspan="2" background="images/simple_04.gif"><table width="445" border="0">
        <tr>
          <td width="439"><div align="center">
              <p>

              <p>
            <%

   Connection conn;
   Statement stm = null;
            String r = "";
            ResultSet rs = null;

            String user=request.getParameter("txtUser");
      String pass=request.getParameter("txtOldPass");
      String newpass=request.getParameter("txtNewPass");


            r = "update PersonalInfo set Password1 ='" + newpass + "' where UserName = '" + user + "' and Password1 = '" + pass+ "'";

            try
            {
            sqlStat="SELECT * from PersonalInfo where UserName='" +user+ "' and Password1='" +pass+ "'";
            out.print(sqlStat);
            Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
            Connection con = DriverManager.getConnection("jdbc:odbc:liwa");
              //  rs.next();
            stm = con.createStatement();
            stm.executeUpdate(r);
            rs = stmt.executeQuery(sqlStat);

            if (!rs.next())
            {
            out.println("you have entered wrong password");
            out.println("<a href=ChangePassword.htm>Click here to try again</a>");
            }
            else
            {
            out.println("Password Changed Successfully<br/>"); 
            out.print("<a href='Admin.htm'> Home </a>");

           }
           }

           rs.close();
           conn.close();
             catch (Exception e){
              out.println("There is an error" + e.getMessage());
           }
%>
              </p>
              <p>&nbsp; </p>
          </div></td>
        </tr>
        <tr>
          <td><div align="justify"><span class="style15"></span></div></td>
        </tr>
    </table></td>
    <td rowspan="3" background="images/simple_05.gif">&nbsp;</td>
  </tr>
  <tr>
    <td height="298" colspan="2" background="images/simple_06.gif"><table width="200" border="0" align="center">
        <tr>
          <td><form name="form2" method="post" action="">
              <table width="200" height="245" border="0" align="center">
                <tr>
                  <td width="122"><div align="right"><span class="style1">Reservation </span></div></td>
                  <td width="68" height="36">&nbsp;</td>
                </tr>
                <tr>
                  <td><div align="right"><span class="style16">Check In Date:</span></div></td>
                  <td height="21">&nbsp;</td>
                </tr>
                <tr>
                  <td colspan="2"><div align="center"><span class="style3">
                      <select name="select" size="1">
                        <option>1</option>
                        <option>2</option>
                        <option>3</option>
                        <option>4</option>
                        <option>5</option>
                        <option>6</option>
                        <option>7</option>
                        <option>8</option>
                        <option>9</option>
                        <option>10</option>
                        <option>11</option>
                        <option>12</option>
                        <option>13</option>
                        <option>14</option>
                        <option>15</option>
                        <option>16</option>
                        <option>17</option>
                        <option>18</option>
                        <option>19</option>
                        <option>20</option>
                        <option>21</option>
                        <option>22</option>
                        <option>23</option>
                        <option>24</option>
                        <option>25</option>
                        <option>26</option>
                        <option>27</option>
                        <option>28</option>
                        <option>29</option>
                        <option>30</option>
                        <option>31</option>
                      </select>
                      <select name="select" size="1">
                        <option>1</option>
                        <option>2</option>
                        <option>3</option>
                        <option>4</option>
                        <option>5</option>
                        <option>6</option>
                        <option>7</option>
                        <option>8</option>
                        <option>9</option>
                        <option>10</option>
                        <option>11</option>
                        <option>12</option>
                      </select>
                      <select name="select" size="1">
                        <option>2007</option>
                        <option>2008</option>
                        <option>2009</option>
                        <option>2010</option>
                      </select>
                  </span><span class="style3"> </span></div></td>
                </tr>
                <tr>
                  <td><div align="right"><span class="style16">Check Out Date:</span></div></td>
                  <td>&nbsp;</td>
                </tr>
                <tr>
                  <td colspan="2"><div align="center"><span class="style3">
                      <select name="select" size="1">
                        <option>1</option>
                        <option>2</option>
                        <option>3</option>
                        <option>4</option>
                        <option>5</option>
                        <option>6</option>
                        <option>7</option>
                        <option>8</option>
                        <option>9</option>
                        <option>10</option>
                        <option>11</option>
                        <option>12</option>
                        <option>13</option>
                        <option>14</option>
                        <option>15</option>
                        <option>16</option>
                        <option>17</option>
                        <option>18</option>
                        <option>19</option>
                        <option>20</option>
                        <option>21</option>
                        <option>22</option>
                        <option>23</option>
                        <option>24</option>
                        <option>25</option>
                        <option>26</option>
                        <option>27</option>
                        <option>28</option>
                        <option>29</option>
                        <option>30</option>
                        <option>31</option>
                      </select>
                      <select name="select" size="1">
                        <option>1</option>
                        <option>2</option>
                        <option>3</option>
                        <option>4</option>
                        <option>5</option>
                        <option>6</option>
                        <option>7</option>
                        <option>8</option>
                        <option>9</option>
                        <option>10</option>
                        <option>11</option>
                        <option>12</option>
                      </select>
                      <select name="select" size="1">
                        <option>2007</option>
                        <option>2008</option>
                        <option>2009</option>
                        <option>2010</option>
                      </select>
                  </span></div></td>
                </tr>
                <tr>
                  <td><div align="right"><span class="style16">Room Type:</span></div></td>
                  <td>&nbsp;</td>
                </tr>
                <tr>
                  <td colspan="2" valign="bottom"><div align="center"><span class="style3">
                      <select name="select" size="1">
                        <option value="King">King</option>
                        <option value="Big Double">Big Double</option>
                        <option value="Small Double">Small Double</option>
                        <option value="Double">Double</option>
                      </select>
                  </span></div></td>
                </tr>
                <tr>
                  <td height="35" colspan="2"><div align="center"><span class="style3">
                      <input type="submit" name="Submit" value="Check Availibility">
                  </span></div></td>
                </tr>
              </table>
          </form></td>
        </tr>
    </table></td>
  </tr>
  <tr>
    <td background="images/simple_07.gif">&nbsp;</td>
    <td colspan="2" background="images/simple_08.gif">&nbsp;</td>
  </tr>
  <tr>
    <td><img src="images/spacer.gif" width="13" height="1" alt=""></td>
    <td><img src="images/spacer.gif" width="194" height="1" alt=""></td>
    <td><img src="images/spacer.gif" width="468" height="1" alt=""></td>
    <td><img src="images/spacer.gif" width="25" height="1" alt=""></td>
  </tr>
</table>
</body>
</html>

but this code doesnt display right, this error display:

An error occurred at line: 70 in the jsp file: /saroo/site/ChangePassAction.jsp
Generated servlet error:
Syntax error, insert "Finally" to complete TryStatement

An error occurred at line: 70 in the jsp file: /saroo/site/ChangePassAction.jsp
Generated servlet error:
Syntax error, insert "}" to complete Block

Generated servlet error:
Syntax error on tokens, delete these tokens

Generated servlet error:
Syntax error on token "finally", delete this token

plllllz help :)

Hi.use this code .it will work correctly.

<%@ page contentType="text/html; charset=iso-8859-1" language="java" import="java.sql.*" errorPage="" %>
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>

<body bgcolor="#EAFFFF">
<p>
  <%! String op,np,name;%>
  <%
name=request.getParameter("name");
op=request.getParameter("op");
np=request.getParameter("np");
Connection con;
Statement st;
ResultSet rs;
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
con=DriverManager.getConnection("jdbc:odbc:m2","","");
st=con.createStatement();
st.executeUpdate("update registration set password='"+np+"' where password='"+op+"' AND name='"+name+"'");
%>
</p>
<p align="center"><strong><font color="#400080"><br>
  <br>
  <br>
  <br>
Your password has been successfully changed<br>
<br>
<br>
</font></strong></p>
<table width="221" align="center">
  <tr>
    <td width="141"><strong><font color="#400040">Your&nbsp;New&nbsp;Password:</font></strong></td>
    <td width="68"><strong><em><font color="#FF80C0"><%=np%></font></em></strong></td>
  </tr>
</table>
<p align="center"><strong><font color="#400080"></font></strong></p>
<p align="center"><strong><font color="#400080"></font></strong></p>
<p>  <%
st.close();
con.close();
}
catch(Exception e)
{
out.println(""+e);
}
%>
</p>
</body>
</html>

Edited by mike_2000_17: Fixed formatting

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.