带有属性但没有值的Struts

带有属性但没有值的Struts

本文介绍了带有属性但没有值的Struts 2 TextField标签的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时删除!!

我有一个格式如下的 html 标签:

I have a html tag in the following format:

<input type="text" name="username" id="username" placeholder="Enter your username" required>

我正在尝试将其转换为由 struts 标记呈现(以便在验证错误时页面重新加载用户输入的值):

I am trying to convert it to be rendered by a struts tag (so that on validation error, the page reloads the value entered by the user):

<s:textfield name="username" id="username" placeholder="Enter your username" required />

不幸的是,struts 抛出了以下异常:

Unfortunately, struts throws the following exception:

org.apache.jasper.JasperException: /index.jsp(58,110) PWC6212: equal symbol expected
    at org.apache.jasper.compiler.DefaultErrorHandler.jspError(DefaultErrorHandler.java:49)
    at org.apache.jasper.compiler.ErrorDispatcher.dispatch(ErrorDispatcher.java:344)
    at org.apache.jasper.compiler.ErrorDispatcher.jspError(ErrorDispatcher.java:101)
    at org.apache.jasper.compiler.Parser.parseAttribute(Parser.java:220)
    at org.apache.jasper.compiler.Parser.parseAttributes(Parser.java:170)
    at org.apache.jasper.compiler.Parser.parseCustomTag(Parser.java:1394)
    at org.apache.jasper.compiler.Parser.parseElements(Parser.java:1636)
    at org.apache.jasper.compiler.Parser.parse(Parser.java:152)
    at org.apache.jasper.compiler.ParserController.doParse(ParserController.java:210)
    at org.apache.jasper.compiler.ParserController.parse(ParserController.java:111)
    at org.apache.jasper.compiler.Compiler.generateJava(Compiler.java:157)
    at org.apache.jasper.compiler.Compiler.compile(Compiler.java:370)
    at org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:595)
    at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:344)
    at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:457)
    at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:351)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:917)
    at org.apache.catalina.core.ApplicationFilterChain.servletService(ApplicationFilterChain.java:398)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:304)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:185)
    at org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter.doFilter(StrutsPrepareAndExecuteFilter.java:88)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:217)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:185)
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:369)
    at org.springframework.security.web.access.intercept.FilterSecurityInterceptor.invoke(FilterSecurityInterceptor.java:109)
    at org.springframework.security.web.access.intercept.FilterSecurityInterceptor.doFilter(FilterSecurityInterceptor.java:83)
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:381)
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:381)
    at org.springframework.security.web.access.ExceptionTranslationFilter.doFilter(ExceptionTranslationFilter.java:97)
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:381)
    at org.springframework.security.web.session.SessionManagementFilter.doFilter(SessionManagementFilter.java:100)
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:381)
    at org.springframework.security.web.authentication.AnonymousAuthenticationFilter.doFilter(AnonymousAuthenticationFilter.java:78)
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:381)
    at org.springframework.security.web.servletapi.SecurityContextHolderAwareRequestFilter.doFilter(SecurityContextHolderAwareRequestFilter.java:54)
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:381)
    at org.springframework.security.web.savedrequest.RequestCacheAwareFilter.doFilter(RequestCacheAwareFilter.java:35)
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:381)

我猜 Struts 不喜欢没有值的必需".如何编辑我的 Struts 标签以附加没有值的必需"文本?我们有一个现有的 javascript 库,它依赖于required"而不是required="""或其他东西的存在.

I'm guessing that Struts does not like the "required" not having a value. How can I edit my Struts tag to append the "required" text without a value? We have an existing javascript library which relies on the presence of "required" and not "required=""" or something else.

推荐答案

这里是任何发现此问题并运行 Struts 2.3.12 或更高版本的人的答案 - 似乎很少有关于此更改的文档在网络上...

在 2.3.12 版本之前,struts2 有一个必需的属性,可以添加到输入字段中.此属性纯粹是为了将字段标记为必需的,并且可用于通过使用 .ftl 文件在字段旁边添加必需的星号/星号(例如)——它没有运行任何验证.在您的代码中可能是这样的:

Prior to version 2.3.12 struts2 had a required attribute which could be added to input fields. This attribute was purely to label the field as required and could be used to add required a required star/Asterisk (for example) next to the field through the use of .ftl files - it did not run any validation. It might have looked like this in your code:

<s:textfield key="name" type="text" required="true"/>

但是在 2.3.12 版本之后, required 属性被 requiredLabel 属性替换.它的工作方式完全相同,可能如下所示:

However after version 2.3.12 the required attribute was replaced with the requiredLabel attribute. It works in exactly the same way and might look like this:

<s:textfield key="name" type="text" requiredLabel="true"/>

这个变化是因为引入了 html5 required 属性.但是请注意,如果您目前想在 struts2 中使用它,您目前无法在不提供值的情况下使用它(正如 html5 规范所说,您可以) - 这似乎破坏了 struts.所以例如这将不起作用:

This change is because of the introduction of the html5 required attribute. However note if you would like to use this in struts2 currently you cannot currently use it without providing a value (as the html5 specification says you can) - this seems to break struts. so for example this will not work:

<s:textfield key="name" type="text" required />

你需要写:

<s:textfield key="name" type="text" required="required" />

这篇关于带有属性但没有值的Struts 2 TextField标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

1403页,肝出来的..

09-07 01:06