strust2+spring3+hibernate整合之路(struts2的简单配置)

来源:互联网 发布:天翼云盘直链源码 编辑:程序博客网 时间:2024/06/04 01:34

1、工作环境:eclipse (struts2.3.8)
2、 所需jar包
基础的jar包
3、项目目录
success.jsp,login.jsp是后来添加的。

4、配置web.xml(这个在下载的struts2里边apps\struts2-blank\WEB-INF 目录下直接拷贝)

     <?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>Struts Blank</display-name>    <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>    <welcome-file-list>        <welcome-file>index.html</welcome-file>    </welcome-file-list></web-app>

5 、 配置struts.xml(这个文件也在struts2文件夹中,我的是在apps\struts2-blank\WEB-INF\classes 也是直接拷贝,其中其他配置不过多说明, 仅为简单的返回sueecss。)

<?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" namespace="/" extends="struts-default">        <action name="hello" class="com.lyk.action.HelloAction">            <result name="success">                /helloworld.jsp            </result>        </action>    </package></struts>

6、添加相对应的HelloAction类

package com.lyk.action;import com.opensymphony.xwork2.ActionSupport;public class HelloAction extends ActionSupport{    @Override    public String execute() throws Exception{        return SUCCESS;    }}

7、 添加helloworld.jsp
8、 结果(http://localhost:8080/Struts2/helloworld.jsp)

0 0