}
return b;
}
public User checkBC(User u) {
Connection conn = null;
PreparedStatement p *** t = null;
ResultSet rs = null;
User tmp = new User();
conn = DBConnection.getConnection();
try {
p *** t = conn.prepareStatement(SQL_SELECT);
p *** t.setString(1, u.getLoginName());
p *** t.setString(2, u.getPassWord());
rs = p *** t.executeQuery();
if (rs.next()) {
tmp.setLoginName(rs.getString(1));
tmp.setUserName(rs.getString(2));
tmp.setAge(rs.getInt(4));
tmp.setAddress(rs.getString(5));
}
} catch (SQLException ex) {
System.out.println(ex.getMessage());
} finally {
cleanDB(rs, p *** t, conn);
}
return tmp;
}
public void cleanDB(ResultSet rs, PreparedStatement p *** t, Connection conn) {
try {
if (rs != null) {
【java窗体软件代码 java窗口程序代码】rs.close();
}
if (p *** t != null) {
p *** t.close();
}
if (conn != null) {
conn.close();
}
} catch (SQLException ex) {
System.out.println(ex.getMessage());
}
}
第3个实体使用者类:User.java
package edu.sys.text.model.entity;
public class User {
private String loginName;
private String userName;
private String passWord;
private int age;
private String address;
public User() {
}
public void setLoginName(String loginName) {
this.loginName = loginName;
}
public void setUserName(String userName) {
this.userName = userName;
}
public void setPassWord(String passWord) {
this.passWord = passWord;
}
public void setAge(int age) {
this.age = age;
}
public void setAddress(String address) {
this.address = address;
}
public String getLoginName() {
return loginName;
}
public String getUserName() {
return userName;
}
public String getPassWord() {
return passWord;
}
public int getAge() {
return age;
}
public String getAddress() {
return address;
}
}
然后编写控制层(C):GetInfoServlet.java
package edu.sys.text.control;
import javax.servlet.*;
import javax.servlet..*;
import java.io.*;
import java.util.*;
import edu.sys.text.model.entity.User;
import edu.sys.text.model.service.UserManager;
public class GetInfoServlet extends HttpServlet {
private static final String CONTENT_TYPE = "text/; charset=GBK";
Initialize global variables
public void init() throws ServletException {
}
Process the HTTP Get request
public void doGet(HttpServletRequest request, HttpServletResponse response) throws
ServletException, IOException {
}
Process the HTTP Post request
public void doPost(HttpServletRequest request, HttpServletResponse response) throws
ServletException, IOException {
String loginName = request.getParameter("loginName");
String passWord = request.getParameter("passWord");
User u = new User();
u.setLoginName(loginName);
u.setPassWord(passWord);
UserManager m = new UserManager();
RequestDispatcher d;
if (m.checkUser(u)) {
User o = m.checkBC(u);
request.setAttribute("JavaBEAN",o);
d = request.getRequestDispatcher("GetInfoUser.jsp");
} else {
d = request.getRequestDispatcher("GetInfoFinale.jsp");
}
d.forward(request, response);
}
Clean up resources
public void destroy() {
}
}
最后,建立表示层(V):包括3个Jsp(登入页面GetInfo.jsp、登入成功页面GetInfoUser.jsp、登入失败页面GetInfoFinale.jsp)
上面的就是Jsp结合Servlet用MVC架构写的使用者登入程式 。
用java编写一个窗体资料输入比较程式
推荐阅读
- 投诉公众号刷阅读,投诉公众号怎么投诉
- 什么颜色拍摄容易失真,什么颜色拍出来最亮
- 固态硬盘怎么设置显示速度,固态硬盘如何设置速度快
- inspire主题wordpress,inspire设置壁纸
- c语言函数什么时候无返值 c语言函数什么时候无返值为0
- 什么u盘适合安装系统,哪种u盘做系统比较好
- 荣耀mgic3可以更新鸿蒙系统吗,荣耀magic3可以升级鸿蒙系统
- mysql数据怎么创建 mysql怎么创建数据表
- 为什么斗鱼只能看原画直播,斗鱼直播为什么清晰度只有一个选项