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登录成功界面

最新文章

  1. Golang汇编命令解读
  2. SPI总线
  3. C#学习系列-抽象方法与虚拟方法的区别
  4. 问题解决——VC 断点 无效 一个可能情况?
  5. 初识C++的类
  6. 开始开发HoloLens应用吧 Start Developing HoloLens Apps Today
  7. ios cocos2d TexturePacker生成文件后的使用方法
  8. DIV设置了固定宽高出现文字(文本)的不能自动换行
  9. CSS3 text-rendering属性
  10. java缓存算法【转】
  11. css样式之背景图片
  12. http cookie
  13. SilkTest天龙八部系列5-类的属性
  14. iOS开发 - 应用内打开第三方应用并传值
  15. VMware中linux与window目录共享
  16. mac地址静态捆绑,防止arp欺骗
  17. Markdown例子
  18. macos 安装sublime text 3,如何安装插件
  19. android 中activity重启的方法
  20. linux上部署jenkins步骤小记

热门文章

  1. 20155237 2016-2017-2 《Java程序设计》第1周学习总结
  2. JAVA Swing开发单机版项目
  3. 用 GSL 求解超定方程组及矩阵的奇异值分解(SVD) 2
  4. idea ssm项目出现日志中文乱码,封装的json中的msg字段中文乱码(但是json封装的bean中的字段不乱码)等其他各种项目下的中文乱码解决方案
  5. 常见面试算法题JS实现-设计一个有getMin功能的栈
  6. Siki_Unity_7-4_高自由度沙盘游戏地图生成_MineCraft_Uniblocks插件(可拓展)
  7. oracle数据库更改字符集
  8. python - 定时清理ES 索引
  9. Acer 4750G安装OS X 10.9 DP4(简版)
  10. runlevel 命令详解