![]() ![]() ![]() ![]() |
|||||
|
|||||
樓主 Ting ![]()
![]() |
-------------------------------------------------------------------------------------------------------------------------------- <%@ page contentType="text/html; charset=utf-8" language="java" import="java.sql.*" errorPage="" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>會員登入</title> </head> <body text="blue"> <% request.setCharacterEncoding("utf-8"); %> <% String url = "jdbc:odbc:market"; Connection conn = null; Statement stmt = null; ResultSet rs = null; Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); conn = DriverManager.getConnection(url); stmt = conn.createStatement(); String username=request.getParameter("username"); String pass=request.getParameter("pass"); if(username.length()<1 || pass.length()<1) { out.println("帳號或密碼錯誤<br><a href='login.jsp'>請再輸入一次</a>"); } else { String sql = " select * from users where username='"+username+"' and password ='"+pass+"'"; rs = stmt.executeQuery(sql); if(rs.next()) { session.setAttribute("username",username); session.setAttribute("password",pass); response.sendRedirect("welcome.jsp"); } else { out.println("帳號或密碼錯誤<br><a href='login.jsp'>請再輸入一次!!</a>"); stmt.close(); conn.close(); } } %> </body> </html> -------------------------------------------------------------------------------------------------------------------------------- <%@ page contentType="text/html; charset=utf-8" language="java" import="java.sql.*" errorPage="" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>會員登入成功</title> </head> <body text="blue"> <% request.setCharacterEncoding("utf-8"); %> <% String username= (String) session.getAttribute("usernmae"); if(username==null || username.length()<1 ) response.sendRedirect("login.jsp"); %> <h1 align="center">歡迎光臨<%= username %>!!</h1><br> <h2 align="center">您成功登入系統</h2><br> </body> </html> |
1樓
最有價值解答
冷月 ![]() |
你這一句串錯字了,改一改看看吧:
String username= (String) session.getAttribute("usernmae"); ---> String username= (String) session.getAttribute("username"); 還有,請不要使用字串連接的方法來撰寫SQL,會有SQL injection 的風險,請使用preparedStatement
本篇文章回覆於2012-05-05 01:18
== 簽名檔 ==
--未登入的會員無法查看對方簽名檔-- |
2樓
作者回應
Ting ![]() |
謝謝您的指教! 我已經自己修正完畢! 不過還是很謝謝你:)
但是 我目前還沒學到您所說的preparedStatement,上網找了一下資料,是指用?代替變數的意思嗎?
本篇文章回覆於2012-05-07 19:22
== 簽名檔 ==
--未登入的會員無法查看對方簽名檔-- |
回覆 |
如要回應,請先登入. |