Struts 第一个Hello页面

在工程目录的src下新建 struts.xml

 

<?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>
    <!--
    <constant name="struts.enable.DynamicMethodInvocation" value="false" />
    <constant name="struts.devMode" value="true" />

    <package name="default" namespace="/" extends="struts-default">

        <default-action-ref name="index" />

        <global-results>
            <result name="error">/error.jsp</result>
        </global-results>

        <global-exception-mappings>
            <exception-mapping exception="java.lang.Exception" result="error"/>
        </global-exception-mappings>

        <action name="index">
            <result type="redirectAction">
                <param name="actionName">HelloWorld</param>
                <param name="namespace">/example</param>
            </result>
        </action>
    </package>

    <include file="example.xml"/>
    -->

    <!-- Add packages here –>

 

    <constant name="struts.devMode" value="true" /><!—devMode: developmentMode开发模式 设成true 则修改了该配置文件可以不用重新部署,自动反馈 —>

 

    <package name="default" namespace="/" extends="struts-default">

<!—namespace的内容就对应浏览器中该web应用后边的路径,这里写的是“/”所以 http://localhost:8080/struts/ 就对应该package-->
    
        <action name="hello">

<!—name 的内容就是上面那个路径后边该写的部分,http://localhost:8080/struts/hello 或者 http://localhost:8080/struts/hello.action都可以访问Hello.jsp-->
            <result>
                /Hello.jsp
            </result>
        </action>
    </package>


</struts>

 

修改web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5" xmlns="
http://java.sun.com/xml/ns/javaee"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
   
http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
    <display-name></display-name>

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

<!— 其源码位置 F:\struts-2.3.15.3-all\struts-2.3.15.3\src\core\src\main\java (参考) -->
    </filter>

    <filter-mapping>
        <filter-name>struts2</filter-name>
       <url-pattern>/*</url-pattern><!-- 所有的访问都会执行这个struts过滤器,也就是转到上面的struts.xml中去处理 -->
    </filter-mapping>

    <welcome-file-list>
        <welcome-file>index.jsp</welcome-file>
    </welcome-file-list>
</web-app>

导入struts例子程序中的所有jar包

WEB-INF下新建Hello.jsp

部署后访问该工程/hello就可以了

 

Eclipse 添加源码可以在导入的jar包上右键属性,然后导入java Source,

同时也可以导入java Doc 说明帮助文档,导入了帮助文档可以在Eclipse中点类F1查看帮助文档

还可以将xml的提示标签导入,一般在jar包解压后会有相应的dtd文件,在Preference中搜索catalog就可以根据路径导入。

 

 

 

关于大致流程,尚学堂的一个图:

image

 

jsp最后经过一些列处理返回给客户端一个页面。

posted @ 2013-12-10 14:10  剑握在手  阅读(293)  评论(0)    收藏  举报
返回顶部↑