0
在jsp Login或Session()中,最好在會話中輸入用戶名或ID?在JSP中使用Id或用戶名
並且我測試了一個servlet還是一個outher jsp頁面?
IM使用在outher jsp頁面的代碼,但我認爲是不是安全
<%if(session.getAttribute("username") == null){%>
<%
String err ;
Connection cnn;
Class.forName(System.getProperty("database.driver","com.mysql.jdbc.Driver"));
cnn = DriverManager.getConnection("jdbc:mysql://localhost:3306/sondage","root", "");
Statement stat1 = cnn.createStatement();
String Username,Password;
Username=request.getParameter("UserName");
Password=request.getParameter("passWord");
//Le nomre de produits
ResultSet resultat = stat1.executeQuery("select * from utilisateur where username ='"+ Username +"' and password = '"+Password+"'");
if (resultat.next()) {
session.putValue("username",Username);
RequestDispatcher rd =request.getRequestDispatcher("vote.jsp");
rd.forward(request, response);
}
else {
RequestDispatcher rd =request.getRequestDispatcher("authentification.jsp?err=1");
rd.forward(request, response);
}
%>
謝謝,先生是否有任何易於使用的SQL注入jar? – David 2011-06-15 20:00:01
編號只需使用'PreparedStatement'而不是'Statement'。另請參閱我在「準備好的陳述」背後的答案。 – BalusC 2011-06-15 20:01:02