eclipse(luna)搭建SSH(struts2+spring4+hibernate4)

准备工作:

java环境

tomcat环境(这里使用tomcat8.0)

eclipse(已添加了server runtime插件)

=================================================

1,eclipse中新建dynamic web project(file-new-other-web),本文项目名称为sshTry

如果target runtime为空,则需要首先通过Eclipse—help—install new software安装几个插件,用来连接本机的tomcat(所有eclipse配置tomcat进行配置)

 

2.  下载 struts spring hibernate

http://struts.apache.org/

http://hibernate.org/orm/releases/

http://repo.springsource.org/release/org/springframework/spring/4.0.0.RELEASE/

3.     创建struts项目(此时不需要spring hibernate)

将struts加压缩包中的jar复制到:(不需要struts2-spring-plugin************,不要放进来)

WEB-INF目录下创建web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app id="WebApp_9" version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee"
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">

	<display-name>sshTry</display-name>

	<filter>
		<filter-name>SSH</filter-name>
		<filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
	</filter>

	<filter-mapping>
		<filter-name>SSH</filter-name>
		<url-pattern>/*</url-pattern>
	</filter-mapping>

	<welcome-file-list>
		<welcome-file>register.jsp</welcome-file>
	</welcome-file-list>

</web-app>

  

src目录下下创建struts.xml

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE struts PUBLIC  
    "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"  
    "http://struts.apache.org/dtds/struts-2.0.dtd">  
  
<struts>  
  
    <include file="struts-default.xml" />  
    <package name="sshTry" extends="struts-default">  
        <action name="register" class="com.fit.sshTry.action.RegisterAction">  
            <result name="input">/register.jsp</result>  
            <result name="success">/succeed.jsp</result>  
            <result name="error">/fail.jsp</result>  
        </action>  
    </package>  
  
</struts>  

  

这里package标记中name属性用作定义一个包名以区分其他人代码,extends属性用于继承一个父包

  action标记中的name属性是用作客户端访问时的路径相当于Servlet's path
  action标记中的class属性则是用作与这个action所对应的aciton类的全路径  
  action标记内result中的name属性为其父标记所对应方法的返回值,不写默认为success
  若返回值与name属性值匹配则完成result标记内指定的路径进行跳转

4 编写基本类

都是基本的get set方法

只有RegisterAction特殊需要写execute()方法

 5 启动tomcat

 地址栏写入http://127.0.0.1:8080/register.jsp

 register.jsp为 struts配置文件中 action  name

原文地址:https://www.cnblogs.com/apache11/p/7762572.html