简单的 JSF 应用程序使引用 Atribute 名称的 Jasper 异常是唯一的



这是我得到的错误日志

   org.apache.jasper.JasperException: /pages/inputname.jsp (line: 3, column: 50) Attribute qualified names must be unique within an element
    org.apache.jasper.compiler.DefaultErrorHandler.jspError(DefaultErrorHandler.java:41)
    org.apache.jasper.compiler.ErrorDispatcher.dispatch(ErrorDispatcher.java:407)
    org.apache.jasper.compiler.ErrorDispatcher.jspError(ErrorDispatcher.java:88)
    org.apache.jasper.compiler.Parser.parseAttributes(Parser.java:171)
    org.apache.jasper.compiler.Parser.parseAttributes(Parser.java:153)
    org.apache.jasper.compiler.Parser.parseCustomTag(Parser.java:1236)
    org.apache.jasper.compiler.Parser.parseElements(Parser.java:1450)
    org.apache.jasper.compiler.Parser.parse(Parser.java:138)
    org.apache.jasper.compiler.ParserController.doParse(ParserController.java:239)
    org.apache.jasper.compiler.ParserController.parse(ParserController.java:102)
    org.apache.jasper.compiler.Compiler.generateJava(Compiler.java:197)
    org.apache.jasper.compiler.Compiler.compile(Compiler.java:372)
    org.apache.jasper.compiler.Compiler.compile(Compiler.java:352)
    org.apache.jasper.compiler.Compiler.compile(Compiler.java:339)
    org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:594)
    org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:344)
    org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:390)
    org.apache.jasper.servlet.JspServlet.service(JspServlet.java:333)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
    com.sun.faces.context.ExternalContextImpl.dispatch(ExternalContextImpl.java:410)
    com.sun.faces.application.ViewHandlerImpl.executePageToBuildView(ViewHandlerImpl.java:469)
    com.sun.faces.application.ViewHandlerImpl.renderView(ViewHandlerImpl.java:140)
    com.sun.faces.lifecycle.RenderResponsePhase.execute(RenderResponsePhase.java:110)
    com.sun.faces.lifecycle.Phase.doPhase(Phase.java:100)
    com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:139)
    javax.faces.webapp.FacesServlet.service(FacesServlet.java:266)
    org.apache.jasper.runtime.PageContextImpl.doForward(PageContextImpl.java:745)
    org.apache.jasper.runtime.PageContextImpl.forward(PageContextImpl.java:716)
    org.apache.jsp.index_jsp._jspService(index_jsp.java:60)
    org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
    org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:419)
    org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:390)
    org.apache.jasper.servlet.JspServlet.service(JspServlet.java:333)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:722)

JSP 页面的代码是

<%@ taglib uri="http://java.sun.com/jsf/html" prefix="h" %>
<%@ taglib uri="http://java.sun.com/jsf/core" prefix="f" %>
<f:loadBundle var="test.bundle.messages" var="msg"/>
<html>
 <head>
  <title>enter your name page</title>
 </head>
 <body>
   <f:view>
     <h1>
      <h:outputText value="#{msg.inputname_header}"/>
     </h1>
     <h:form id="helloForm">
      <h:outputText value="#{msg.prompt}"/>
      <h:inputText value="#{personBean.personName}" />
      <h:commandButton action="greeting" value="#{msg.button_text}" />
     </h:form>
   </f:view>
 </body>
</html> 

对于消息属性文件,它是

inputname_header=JSF KickStart
prompt=Tell us your name:
greeting_text=Welcome to JSF
button_text=Say Hello
sign=!

这里出了什么问题?

错误包含行号和字符位置:

/
pages/inputname.jsp (行: 3, 列: 50)

就是这样

        <f:loadBundle var="test.bundle.messages" var="msg"/>
-------------------------------------------------^

错误消息显示:

属性限定名称在元素中必须是唯一的

再看一遍,你已经声明了两次var属性。第一个应该是basename.相应地修复它:

        <f:loadBundle basename="test.bundle.messages" var="msg"/>

具体问题无关,自2.5年前JSF已经升级到JSF 2.0,JSP已被Facelets取代。我强烈建议您更新您的课程/学习材料/书籍/教程。它们已经过时了。

相关内容

  • 没有找到相关文章

最新更新