zoukankan      html  css  js  c++  java
  • Struts2第一个工程helloStruts极其基本配置

    前面已经准备好了Struts-2.3.15,现在就可以直接搭建Struts2的工程了。前面http://blog.csdn.net/huangchnegdada/article/details/9179041有对Struts-2.3.15的准备工作的详述。

    首先打开MyEclispe新建一个Web Project,名字就叫Struts2_0100_Introduction,接下来就是配置Struts2的框架:

    然后解压E:Study ToolsStruts2struts-2.3.15apps下的struts2-blank.war


    里面有struts的最基本的配置,首先找到E:Study ToolsStruts2struts-2.3.15appsstruts2-blankWEB-INF下面的web.xml文件,将其拷贝到工程下的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">
    
        <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>hello.jsp</welcome-file>
        </welcome-file-list>
    
    </web-app>
    

    然后将E:Study ToolsStruts2struts-2.3.15appsstruts2-blankWEB-INFclasses下的struts.xml文件考到工程的src文件夹中。

    最后工程的结构如下:


    struts中的文件代码如下:

    <?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"/>
    	 -->
    	 <!-- 此段代码非常关键,它可以让你在修改代码后,不需要重新启动服务器 -->
    	 <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="hello_struts">
                <result>
                    /hello.jsp
                </result>
            </action>
        </package>
        <!-- Add packages here -->
    	
    </struts>
    

    将此项目部署起来后,在Web Brower中输入:http://localhost:8080/Struts2_0100_Introduction/hello_struts后会出现下面结果,,就说明成功了。


  • 相关阅读:
    Hibernate4究竟怎么玩目录
    Hibernate检索策略之5.2多对一单向关联检索策略——Hibernate4究竟怎么玩
    Struts2 OGNL表达式中调用java静态方法无效的解决办法
    JDBC API中的execute返回值问题
    Hibernate检索策略之5.1类级别检索策略——Hibernate4究竟怎么玩
    PowerDesigner逆向工程mysql
    三种批量增加的性能分析
    Apache FtpServer的使用
    杭电1013
    杭电1008
  • 原文地址:https://www.cnblogs.com/dyllove98/p/3157177.html
Copyright © 2011-2022 走看看