我有以下格式的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 =”“”或其他东西。
答案 0 :(得分:4)
您需要完全设置“required”属性:
<s:textfield ... required="required" />
这就是JSP / XHTML的工作方式,AFAIK。
我无法想象JS库是否会关心是否存在值。