標籤:etc super uid bean ret xtend new UI file
the java layout is like this:
the web.xml:
the login.jsp:
success.jsp:
Acount.java:
the Login.java:
package com.userinfo;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
public class Login extends HttpServlet {
/**
*
*/
private static final long serialVersionUID = 1L;
@Override
protected void doPost(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException {
// TODO Auto-generated method stub
// super.doPost(req, resp);
// HttpSession session=req.getSession();
// Acount acount=new Acount();
// String user_name=req.getParameter("username");
// String pass_wd=req.getParameter("passwd");
// try {
// Class.forName("com.mysql.jdbc.Driver");
// Connection conn=DriverManager.getConnection("jdbc:mysql://localhost/ncpss_ncpss", "root", "wuxibo");
// Statement st=conn.createStatement();
// ResultSet rs=st.executeQuery("select * from userinfo where username= ‘"+user_name+"‘ and passwd=‘"+pass_wd+"‘");
// if (rs.next()){
// acount.setUsername(user_name);
// acount.setPasswd(pass_wd);
// session.setAttribute("acount", acount);
// req.getRequestDispatcher("success.jsp").forward(req, resp);
// return;
// }
// resp.sendRedirect("login.jsp");
// return;
// Acount acount=new Acount();
// HttpSession session=req.getSession();
// String user_name=req.getParameter("username");
// String pass_wd=req.getParameter("passwd");
// try {
// Class.forName("com.mysql.jdbc.Driver");
// Connection conn=DriverManager.getConnection("jdbc:mysql://localhost/ncpss_ncpss", "root", "wuxibo");
// Statement st=conn.createStatement();
// ResultSet rs=st.executeQuery("select * from userinfo");
// while(rs.next()){
// String userName=rs.getString("username");
// String passWd=rs.getString("passwd");
// if (user_name.equals(userName)&&pass_wd.equals(passWd)){
// acount.setUsername(user_name);
// acount.setPasswd(pass_wd);
// session.setAttribute("acount", acount);
// req.getRequestDispatcher("success.jsp").forward(req, resp);
// return;
// }
// }
// resp.sendRedirect("login.jsp");
// return;
Acount acount=new Acount();
HttpSession session=req.getSession();
String user_name=req.getParameter("username");
String pass_wd=req.getParameter("passwd");
try {
Class.forName("com.mysql.jdbc.Driver");
Connection conn=DriverManager.getConnection("jdbc:mysql://localhost/ncpss_ncpss", "root", "wuxibo");
Statement st=conn.createStatement();
ResultSet rs=st.executeQuery("select * from userinfo");
while(rs.next()){
String userName=rs.getString("username");
String passWd=rs.getString("passwd");
if (user_name.equals(userName)&&pass_wd.equals(passWd)){
acount.setUsername(user_name);
acount.setPasswd(pass_wd);
session.setAttribute("acount", acount);
req.getRequestDispatcher("success.jsp").forward(req, resp);
return;
}
}
resp.sendRedirect("login.jsp");
return;
} catch (ClassNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException {
// TODO Auto-generated method stub
// super.doGet(req, resp);
}
}
a simple java login using jsp, servlet, javabean