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

一、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()方法未初始化成员变量。


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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值