首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > 编程 >

struts学习-配备struts

2012-11-06 
struts学习---配置struts开始学习框架,struts2,先来一个helloworld程序配置struts.步骤一:官网下载struts,

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文件中。

struts学习-配备struts

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

struts学习-配备struts

这样算是配置好了,可以开写了,打开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可省略。

热点排行