JSPサーブレットプロジェクトでアプリケーションを動作させるために、次のコードスニペットをどこに埋め込む必要があるのかを知る必要がありますか?さらにMVCアーキテクチャを使用しています。これは正しいかどうかを知る必要があります私はjspに新しい。JSPログインページでパスワード有効期限検証を作成する方法は?
public class PsswordSerializability {
private java.util.Date lastSignupdate;
public boolean isExpired(String password){
boolean check = false;
//Date lastSignupdate = new Date();
Calendar cal = Calendar.getInstance();
cal.setTime(lastSignupdate);
cal.add(Calendar.DATE, 45);
java.util.Date expirationDate = cal.getTime();
if(lastSignupdate < expirationDate){
System.out.println("reset password");
}
else {
System.out.println("success");
}
return check;
}}
上記は、実行する必要があるロジックのコードです(パスワードは45日後にリセットしてダイアログボックスを表示する必要があります)。次に、SQLのクエリ部分のJSPコードです。
<form>
<p>
<input type="text" name="oldpwd" placeholder="Old Password">
</p>
<p>
<input type="password" name="newpwd" placeholder="New Password">
</p>
<p>
<input type="password" name="cnfrmpwd" placeholder="Confirm Password">
</p>
<br>
<input type="submit" name="submit" value="RESET">
<%
String oldpass = request.getParameter("password");
String newpass = request.getParameter("newpwd");
String conpass = request.getParameter("cnfrmpwd");
String username = request.getParameter("username");
Connection con;
ResultSet rs = null;
try {
Class.forName("com.mysql.jdbc.Driver");
con = DriverManager.getConnection("jdbc:mysql://localhost:3306/hospitalmanagementsystemdb");
PreparedStatement ps = con.prepareStatement("SELECT * FROM com.hospitalsystem.dao.UserDAO WHERE Password='" + oldpass + "'");
rs = ps.executeQuery();
while (rs.next()) {
username = rs.getString(1);
newpass = rs.getString(2);
}
if (oldpass!=null&&newpass!=null&&newpass.equals(oldpass)) {
PreparedStatement ps1 = con.prepareStatement("UPDATE com.hospitalsystem.dao.UserDAO SET Password='" + newpass + "' where Username='" + username + "'");
ps1.executeUpdate();
%>
<p>Password has been Reset</p>
<%response.sendRedirect("index.jsp"); %>
<% } else {%>
<p>Password change failed. Try again!</p>
<% }
} catch (Exception e) {
out.println(e);
}
%>
</div>
私はどのコードをサーブレットなどとして使用すべきかわかりません。ここで何をしなければならないか説明してください。
サーバーに接続している間にすべてのユーザーデータを含むオブジェクトであるセッションを使用する必要があります。あなたはそれに期限(日/時間など)を与えて、それに応じて反応することができます –