您的位置:首页 > 编程语言 > Java开发

《轻量级Java EE 企业应用实战(第4版)——Struts2+Spring 4+Hibernate》 李刚 第三章 Struts2 开发流程 错误解决

2015-07-03 18:41 489 查看
一、struts.xml文件错误

分为以下几种:

1.struts.xml文件名错误。

2.struts.xml文件放置路径错误。一定要将该文件放置在src目录下,编译成功后,要确认是否编译到classes目录中。

3.struts.xml文件内容错误。下面给出一个正确的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.custom.i18n.resources" value="mess" />

<!-- 支持动态方法调用 -->
    <constant name="struts.enable.DynamicMethodInvocation" value="false" />

<!-- 指定国际化编码所使用的字符集 -->
<constant name="struts.i18n.encoding" value="GBK"/>

<!-- 开启开发者模式 -->
    <constant name="struts.devMode" value="true" />
    
    <package name="liuyy" extends="struts-default" namespace="/">
        <action name="login" class="liuyy.test.app.action.LoginAction">
        	<result name="input">login.jsp</result>
        	<result name="error">error.jsp</result>
        	<result name="success">welcome.jsp</result>
        </action>
    </package>
</struts>


 

二、如果排除了struts.xml文件的问题,还有一种可能就是,在web.xml文件中的<welcome-file>信息中是否配置了自己工程的启动页面。

<?xml version="1.0" encoding="GBK"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:web="http://xmlns.jcp.org/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd http://xmlns.jcp.org/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_9" version="2.4">
 
  <welcome-file-list>
  	<welcome-file>login.jsp</welcome-file>
  </welcome-file-list>
  
  <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>
</web-app>


 

《轻量级Java EE 企业应用实战(第4版)——Struts2+Spring 4+Hibernate》

第三章 Struts2 开发流程 

错误:

1.There is no Action mapped for namespace [/] and action name [success] associated with context path

2.LoginAction的execute()方法未初始化成员变量。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: