struts学习---配置struts

           开始学习框架,struts2,先来一个helloworld程序配置struts.

           步骤一:官网下载struts,建一个web工程

           步骤二:在下载的struts解压文件中找到apps文件夹,在这个文件中是struts的示例程序,打开文件,将里面的struts-blank.war解压,在解压文件中找到WEN-INF文件夹中的classes文件夹,里面有一个struts.xml文件,复制到自己工程的src下面。

           步骤三:在刚才的WEB-INF目录下有一个web.xml文件,打开,将里面的关于filter的内容拷到自己的web.xml文件中。


         步骤四:将需要的jar文件复制过来,在lib文件夹中找到这几个jar文件。


这样算是配置好了,可以开写了,打开struts.xml文件,将struts中的内容注释掉,就可以照着他的格式写hello程序了,

代码如下:

<?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="false" />

    <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"/>-->
    
    
     <package name="default" namespace="/" extends="struts-default">

      

        <action name="hello">
            <result>
               /Hello.jsp
            </result>
        </action>
    </package>
    <!-- Add packages here -->

</struts>

这样在新建一个Hello.jsp文件,文件内容为hello world。这样就完成了,查看,工程右击选择debug as 选择 MyEclipse Server Application,选择服务器,这样就可以了,访问的路径为http://localhost:8080/工程名/action的name值.action   ,其中.action可省略。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值