Eclipse中搭建SSH环境

本文详细介绍了如何在Eclipse中搭建SSH(Struts2、Spring、Hibernate)环境。从导入必要的jar包开始,逐步讲解了Struts2、Hibernate和Spring的配置,以及它们之间的整合过程,包括实体类、配置文件的设置,最后实现事务处理器。通过此教程,读者可以掌握SSH框架的搭建步骤。
摘要由CSDN通过智能技术生成

工具:eclipse+mysql

SSH版本:struts-2.3.16.1   spring-framework-4.2.2.RELEASE   hibernate-release-5.2.2.Final 

本人观看视频并按照视频步骤后写出的,视频链接:点击打开链接,侵权必删

一、导入jar包

新建web项目“ssh”,默认点击“下一步”,在最后勾选“web.xml”复选框

在src目录中新建四个包,com.ssh.action,com.ssh.dao,com.ssh.entity,com.ssh.service

百度“SSH整合jar包”下载,将其导入“lib”文件夹中

二、搭建Struts2

在com.ssh.action包中新建“UserAction.java”

public class UserAction extends ActionSupport {
	
	public String login() {
		return "login";
	}
}

在src目录下新建Struts2核心配置文件“struts.xml”,并配置“UserAction.java”

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC
    "-//Apache Software Foundation//DTD Struts Configuration 2.3//EN"
    "http://struts.apache.org/dtds/struts-2.3.dtd">
<struts>
	
	<package name="default" extends="struts-default" >
		
		<action name="user_login" class="com.ssh.action.UserAction" method="login">
			<result name="login">/login.jsp</result>
		</action>
	
	</package>


</struts>

在“web.xml”中配置struts2过滤器

<?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">
  
   <!-- 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>/*</url-pattern>
  </filter-mapping>
  
  <display-name>ssh</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>
</web-app>

struts2搭建完成

三、搭建Hibernate

在com.ssh.entity中创建实体类“User.java”

public class User {
	
	private int uid;
	private String username;
	public int getUid() {
		return uid;
	}
	public void setUid(int uid) {
		this.uid = uid;
	}
	public String getUsername() {
		return username;
	}
	public void setUsername(String username) {
		this.username = username;
	}

}

在com.ssh.entity中创建“User.hbm.xml”

<?xml version="1.0" encoding="UTF-8"?>
<
  • 1
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值