首页 > 代码库 > ssh结合使用
ssh结合使用
springxml配置
<?xml version="1.0" encoding="UTF-8"?> <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://xmlns.jcp.org/xml/ns/javaee" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd" id="WebApp_ID" version="3.1"> <display-name>ssh02</display-name> <welcome-file-list> <welcome-file>index.html</welcome-file> <welcome-file>index.htm</welcome-file> <welcome-file>index.jsp</welcome-file> <welcome-file>default.html</welcome-file> <welcome-file>default.htm</welcome-file> <welcome-file>default.jsp</welcome-file> </welcome-file-list> <!--配置struts过滤器 --> <filter> <filter-name>struts2</filter-name> <filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class> </filter> <filter-mapping> <filter-name>struts2</filter-name> <url-pattern>*.action</url-pattern> </filter-mapping> <!-- 配置spring监听器 --> <listener> <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> </listener> <context-param> <param-name>contextConfigLocation</param-name> <param-value>classpath:spring.xml</param-value> </context-param> </web-app>
UserAction 类
package com.qianfeng.action; import com.qianfeng.dao.UserDao; import com.qianfeng.entity.User; public class UserAction { private User u = new User(); private UserDao ud; public UserDao getUd() { return ud; } public void setUd(UserDao ud) { this.ud = ud; } public void setU(User u) { this.u = u; } public User getU() { return u; } public String login() { String str = "index"; if (ud.login(u)) { str = "ss"; } return str; } }
UserDao类
package com.qianfeng.dao; import org.hibernate.Session; import org.hibernate.SessionFactory; import org.hibernate.query.Query; import com.qianfeng.entity.User; public class UserDao { private SessionFactory sf; public void setSf(SessionFactory sf) { this.sf = sf; } public boolean login(User u) { Session session = sf.openSession(); Query query = session.createQuery("from User where acount=? and pwd=?"); query.setString(0, u.getAcount()); query.setString(1, u.getPwd()); Object rs = query.uniqueResult(); session.close(); return rs == null ? false : true; } }
User类
package com.qianfeng.entity; import java.io.Serializable; public class User implements Serializable { private int id; private String acount; private String pwd; public User() { super(); } public String getAcount() { return acount; } public User(String acount, String pwd) { super(); this.acount = acount; this.pwd = pwd; } public void setAcount(String acount) { this.acount = acount; } public String getPwd() { return pwd; } public void setPwd(String pwd) { this.pwd = pwd; } public int getId() { return id; } public void setId(int id) { this.id = id; } }
login 登录界面
ss登录成功界面
ssh结合使用
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。