赞
踩
一步一教你搭建SSH框架,实现简单的增删改查功能
一、首先创建一个Java web项目,并按下图建好项目目录
二、在网上搜索ssh所需jar包,并将其放到WEB_INF下的lib里面(这里截图了部分)
三、如下图配置web.xml(添加spring监听器以及struts过滤器等)
- <?xml version="1.0" encoding="UTF-8"?>
- <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" id="WebApp_ID" version="3.0">
- <display-name>ssh</display-name>
- <welcome-file-list>
- <welcome-file>index.jsp</welcome-file>
- </welcome-file-list>
-
- <!-- ########## 过滤器 ########## -->
- <!-- OpenSessionInView -->
- <filter>
- <filter-name>OpenSessionInView</filter-name>
- <filter-class>
- org.springframework.orm.hibernate3.support.OpenSessionInViewFilter
- </filter-class>
- <init-param>
- <param-name>singleSession</param-name>
- <param-value>true</param-value>
- </init-param>
- </filter>
- <filter-mapping>
- <filter-name>OpenSessionInView</filter-name>
- <url-pattern>/*</url-pattern>
- </filter-mapping>
- <!-- 配置字符过滤 -->
- <filter>
- <filter-name>setCharactor</filter-name>
- <filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
- <init-param>
- <param-name>encoding</param-name>
- <param-value>UTF-8</param-value>
- </init-param>
- </filter>
- <filter-mapping>
- <filter-name>setCharactor</filter-name>
- <url-pattern>/*</url-pattern>
- </filter-mapping>
-
- <!-- 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>*.do</url-pattern>
- <url-pattern>*.jsp</url-pattern>
- <dispatcher>FORWARD</dispatcher>
- <dispatcher>REQUEST</dispatcher>
- <dispatcher>INCLUDE </dispatcher>
- </filter-mapping>
- <!-- spring -->
- <context-param>
- <param-name>contextConfigLocation</param-name>
- <param-value>
- /WEB-INF/classes/applicationContext.xml
- </param-value>
- </context-param>
-
- <!-- ########## 监听器 ########## -->
- <!-- spring监听器 -->
- <listener>
- <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
- </listener>
-
- </web-app>
四、在bo包建立User实体类及其Hibernate映射文件
User.java
- package com.suo.bo;
-
- /**
- * User entity. @author MyEclipse Persistence Tools
- */
-
- public class User implements java.io.Serializable {
-
- // Fields
-
- private Integer id;
- private String name;
- private String password;
- private String email;
- private String address;
- // Property accessors
-
- public Integer getId() {
- return this.id;
- }
-
- public void setId(Integer id) {
- this.id = id;
- }
-
- public String getName() {
- return this.name;
- }
-
- public void setName(String name) {
- this.name = name;
- }
-
- public String getPassword() {
- return this.password;
- }
-
- public void setPassword(String password) {
- this.password = password;
- }
-
- public String getEmail() {
- return this.email;
- }
-
- public void setEmail(String email) {
- this.email = email;
- }
-
- public String getAddress() {
- return this.address;
- }
-
- public void setAddress(String address) {
- this.address = address
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。