gpt4 book ai didi

struts2 - 具有属性但没有值的 Struts 2 TextField 标记

转载 作者:行者123 更新时间:2023-12-04 19:52:35 24 4
gpt4 key购买 nike

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

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

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

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

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

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=""”或其他东西的存在。

最佳答案

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

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

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

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

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

此更改是因为引入了 html5 必需属性。但是请注意,如果您目前想在 struts2 中使用它,则当前不能在不提供值的情况下使用它(正如 html5 规范所说的那样) - 这似乎破坏了 struts。所以例如这不起作用:

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

你需要写:

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

关于struts2 - 具有属性但没有值的 Struts 2 TextField 标记,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12606846/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com