我Change Password
使用 JSP 创建了一个表单,以及一个 servlet 页面来操作数据并将其输入数据库。这是一个内部网站(内部网),因此数据库已经包含Email, FName, LName
所有用户的详细信息。只有密码字段为空。我要做的是,在用户填写他们的电子邮件地址、密码、确认并按下提交按钮后,servlet 页面应该更新当前电子邮件的密码字段。不幸的是,在所有情况下,用户似乎都被重定向到ChangeError.jsp
. 请找到随附的两个文件。(ChangePassword.JSP
和ChangePassword.Servlet
)。任何帮助将非常感激。
//ChangePassword.jsp
<FORM ACTION="ChangePassword" METHOD="GET">
<div id="login_box">
<div id="login_header">
Login
</div>
<div id="form_val">
<div class="label">Email:</div>
<div class="control"><input type="text" name="Email" id="Email"/></div>
<div class="label">Password:</div>
<div class="control"><input type="password" name="Password" id="Password"/></div>
<div class="label">Confirm Password:</div>
<div class="control"><input type="password" name="Password" id="Password"/></div>
<div style="clear:both;height:0px;"></div>
<div id="msgbox"></div>
</div>
<div id="login_footer">
<!-- <script type="text/javascript">
function closewindow() {
window.close()
}
</script>-->
<label>
<input type="submit" onclick="location.href='http://localhost:8080/IntegrateAll/Index.jsp'" window.close();" name="Submit" id="Submit" value="Submit" class="send_button" />
</label>
</div>
</div>
//ChangePassword.servlet
import java.io.IOException;
import javax.servlet.*;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.sql.DataSource;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.PreparedStatement;
import javax.naming.*;
public class ChangePassword extends HttpServlet {
private static final long serialVersionUID = 1L;
public ChangePassword() {
super();
}
protected void doGet(HttpServletRequest request,
HttpServletResponse response) throws ServletException, IOException {
String Email = request.getParameter("Email");
String Password = request.getParameter("Password");
String CPassword = request.getParameter("Password");
Connection con = GetConnectToDb();
boolean flag = CheckLogin(Password,CPassword,Email,con);
if(flag==true){
gotoPage("/LoginPage.jsp",request,response);
}
else{
gotoPage("/ChangeError.jsp",request,response);
}
}
public void gotoPage(String address, HttpServletRequest request,
HttpServletResponse response) throws ServletException, IOException {
RequestDispatcher dispatcher = getServletContext().getRequestDispatcher(address);
dispatcher.forward(request, response);
}
public boolean CheckLogin(String Password, String CPassword,String Email, Connection con) {
if (Password != null && CPassword != null && Email !=null) {
try {
PreparedStatement ps = con.prepareStatement("UPDATE PUBLIC.IAUSERS SET Password = ('"+Password+"') WHERE Email='"+Email+"'");
ResultSet rs = ps.executeQuery();
while(rs.next()) {
return true;
}
} catch (Exception e) {
}
}
return false;
}
public Connection GetConnectToDb() {
try {
InitialContext ctx = new InitialContext();
Connection con = null;
DataSource ds = (DataSource) ctx.lookup("java:/DefaultDS");
con = ds.getConnection();
return con;
} catch (Exception e) {
return null;
}
}
protected void doPost(HttpServletRequest request,
HttpServletResponse response) throws ServletException, IOException {
}}