简单的 JSF 应用程序给出 Jasper 异常,引用属性名称是唯一的

发布于 2024-11-07 16:50:13 字数 3740 浏览 0 评论 0原文

这是我得到的错误日志

   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> 

对于 messages.properties 文件,它是

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

这里出了什么问题?

This is the Error log i got

   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)

The code for the JSP page is

<%@ 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> 

And for the messages.properties file it is

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

Whats going wrong here?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

淡紫姑娘! 2024-11-14 16:50:13

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

/pages/inputname.jsp (line: 3, column: 50)

因此,

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

错误消息显示:

Attribute qualified names must be unique within an element

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

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

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

The error contains the line number and the character position:

/pages/inputname.jsp (line: 3, column: 50)

That's thus

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

The error message says:

Attribute qualified names must be unique within an element

Look once again, you've declared var attribute twice. The first one should have been basename. Fix it accordingly:

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

Unrelated to the concrete problem, since over 2.5 years ago JSF has been upgraded to JSF 2.0 and JSP has been succeeded by Facelets. I'd strongly recommend to refresh your course/learning materials/books/tutorials. They are out of date.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文