zl程序教程

您现在的位置是:首页 >  其他

当前栏目

用myeclipse首次配Struts的错误

错误 首次 myeclipse struts
2023-09-27 14:25:31 时间

首先下载架包

我一开始下载的架包是
struts-2.5.16-all.zip
struts-2.5.16-lib.zip
虽然解压成功了,但是缺少核心文件xwokr-core.2.3.4.jar,而这个包jar包是核心包,因为,虽然通过builderpath添加到myeclipse中,但是,不起作用,总是报错,以为我下载了这个jar包:struts-2.3.34-min-lib.zip,如果有需要的话,可以通过这个链接获得:

链接: https://share.weiyun.com/5BYZRCe (密码:qGbH)


创建web项目

网上都在说用myeclipse中的project facets来创建,但是这样的效果不好,极容易报错的,因而,我们将架包下载下来,添加到项目中。


在webxml当中进行配置
<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>

配置struts.xml

ps:struts.xml要放在src中,不然classpath找不到,也会报错的

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.1//EN" "http://struts.apache.org/dtds/struts-2.1.dtd">
<struts>
    <!-- 是否启用开发模式 -->
    <constant name="struts.devMode" value="true" />
    //name和namespace的名称一般是一致的
    <package name="front" namespace="/front" extends="struts-default">
        <action name="hello">
            <result>/result.jsp</result>
        </action>
    </package>
</struts>