IT忍者神龟之Struts2.xml配置完全正确流程能走通但是有红叉解决

一:Multiple annotations found at this line:Undefined
actionName  
parameter  Undefined
actionnamespace  parameter

这个红色叉叉报错:

Multiple annotations found at this line:

- Undefined actionName

parameter

- Undefined actionnamespace

parameter

但是不影响功能,但是配置多了,很难看

自己网上找了很多类似的资料

这样的错误的原因有很多,我先列出我所知道的原因

另外一个是我自己项目的原因,我的原因就在于自己的第一个没大写

这是改完之后的图

二:struts2.xml中使用chain和redirectAction这两个注意事项

当在struts.xml中使用chain和redirectAction这两个类型结果的时候,会报检查错误!

Multiple annotations found at this line:

-
Undefined actionnamespace

parameter

-
Undefined actionName parameter

相信不少朋友会被这个错误折腾的很难受吧,现在说下解决方案,在百度和google上搜了很久,国外网站也看了下,半天都没找到解决方法,后来无意中在apache的网站上看到了struts2 chain的使用说明,仔细读了一下,就想到了一个办法,或许可以解决,于是就测试了一下,发现问题完全解决了,现在来说下一我的解决方法。

chain结果类型有4个属性,分别是:

actionName
(default) - the name of the action that will be chained to

namespace
- used to determine which namespace the Action is in that we‘re chaining. If namespace is null, this defaults to the current namespace

method
- used to specify another method on target action to be invoked. If null, this defaults to execute method

skipActions
- (optional) the list of comma separated action names for the actions that could be chained to

其中actionName和namespace是必不可少的,否则就会报错。所以我在项目中就写成如下形式:

<package name="struts" extends="struts-default" namespace="/bg">

<action
name="login" class="loginAction">

<result
type="chain">

<param
name="actionName">index</param>

<param
name="namespace">/bg</param>

</result>

</action>

</package>

但是这么写就有一个问题,我的项目比较简单,不想使用命名空间,于是我就想怎么解决这个问题呢,在看官方文档的时候我发现这么一句话:

A root namespace ("/") is also supported. The root is the namespace when a request directly under the context path is received. As with other namespaces, it will fall back to the default ("")
namespace if a local action is not found.

于是我就想,用"/"代替"/bg"不就可以解决问题了么。然后就把代码写成如下形式

<package name="struts" extends="struts-default" namespace="/">

<action
name="login" class="loginAction">

<result
type="chain">

<param
name="actionName">index</param>

<param
name="namespace">/</param>

</result>

</action>

</package>

好了说到这里我想大家也都明白了该怎么解决chain和redirectAction这两个类型结果(type-result)报检查错误(validation)的问题了吧!

有多的不对的地方还请大家多多指教!!

时间: 2024-07-29 01:50:05

IT忍者神龟之Struts2.xml配置完全正确流程能走通但是有红叉解决的相关文章

【maven】 pom.xml内容没有错,但一直报错红叉 解决办法

[架构设计][maven] pom.xml内容没有错,但一直报错红叉 解决办法 [maven] pom.xml内容没有错,但一直报错红叉 解决办法 1.首先看一下下面的这两个项目,一个是新建的,一个是原来的老项目 2.myEcplise中是点击如下图 Maven4MyEcplise, Ecplise中也是右键,只不过点击Mavene而已,两个一样 3. 强制更新Maven 4.一会 红叉就消失了

Struts2 XML配置详解

struts官网下载地址:http://struts.apache.org/ 1.    深入Struts2的配置文件 本部分主要介绍struts.xml的常用配置. 1.1.    包配置: Struts2框架中核心组件就是Action.拦截器等,Struts2框架使用包来管理Action和拦截器等.每个包就是多个Action.多个拦截器.多个拦截器引用的集合. 在struts.xml文件中package元素用于定义包配置,每个package元素定义了一个包配置.它的常用属性有: l name

解决struts2中validation.xml配置无效的问题

解决struts2中validation.xml配置无效的问题,我使用了xml的验证,却始终发现无法生效,后面发现才是xml的头文件的格式问题,修改了一下就好了. 成功的xml <!DOCTYPE validators PUBLIC "-//Apache Struts//XWork Validator 1.0.2//EN" "http://struts.apache.org/dtds/xwork-validator-1.0.2.dtd"> <val

struts2 实现过程和xml配置

实现过程: 当Web容器收到 请求(HttpServletRequest)它将请求传递给一个标准的的过滤链包括 (ActionContextCleanUp)过滤器,然后经过Other filters(SiteMesh ,etc),接下来需要调用FilterDispatcher核心控制器,然后它调用ActionMapper确定请求哪个Action,ActionMapper返回一个收集Action详细信息的ActionMaping对象. 接下来FilterDispatcher将控制权委派给Actio

struts2拦截器-自定义拦截器,放行某些方法(web.xml配置)

一.web.xml配置 <filter> <filter-name>encodingFilter</filter-name> <filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class> <init-param> <param-name>encoding</param-name> <param-val

【struts2.5配置】web.xml配置

一.引用jar包 1. 将下载好的struts下的核心类库复制到/WEB-INF/lib目录下 二.web.xml配置 check your struts2-core-x.x.jar version. -->if it is struts2-core-2.5.jar then change your filter class tag value in web.xml to <filter-class> org.apache.struts2.dispatcher.filter.Struts

struts2 web.xml配置访问404

初学Struts2,在配置完访问页面时发现访问此WEB工程的任何页面都报404错误. 发现在web.xml中只要配置filter就会出现此问题.在网上找了很多方法,发现是jar包的原因,我用的是官网下载的2.55all包,并把所有的jar包了导进去所以出现了这个问题.最终解决办法, 删除struts2-spring-plugin-2.5.5包即可

struts2对action中的方法进行输入校验---xml配置方式(3)

上面两篇文章已经介绍了通过编码java代码的方式实现action方法校验,这里我们介绍另外一种方式:xml配置文件 首先我们来看一个例子: ValidateAction.java: package com.itheima.action; import com.opensymphony.xwork2.ActionSupport; public class ValidateAction extends ActionSupport { private String username; private

Struts2 之 Validation 拦截器 基于XML配置方式实现(验证框架)

基于XML配置方式实现输入校验 I:定义Action *  要继承ActionSupport或者实现Validateable接口: II:配置struts_validate.xml文件 *  验证出错转向的页面                struts.xml配置<result name=“input”>/validate/loginxml.jsp</result>                  其中input转向是在action中已经定义好的. III:配置验证的xml文件