如何使用设置 JSP 的区域设置?

发布于 2024-10-02 23:31:50 字数 2418 浏览 11 评论 0原文

我正在尝试在 JSP 中设置本地。

我想我可以做这样的事情:

<fmt:setLocale value="${param['local']}" scope="session"/>

Java 自己的页面topic 似乎说了这么多。

但是,当我执行此操作时,我得到:

HTTP Status 500 -

type Exception report

message

description The server encountered an internal error () that prevented it from fulfilling this request.

exception

org.apache.jasper.JasperException: /pages/ResourceBundlesJSTL.jsp(11,0) According to TLD or attribute directive in tag file, attribute value does not accept any expressions
 org.apache.jasper.compiler.DefaultErrorHandler.jspError(DefaultErrorHandler.java:40)
 org.apache.jasper.compiler.ErrorDispatcher.dispatch(ErrorDispatcher.java:407)
 org.apache.jasper.compiler.ErrorDispatcher.jspError(ErrorDispatcher.java:148)
 org.apache.jasper.compiler.Validator$ValidateVisitor.checkXmlAttributes(Validator.java:1232)
 org.apache.jasper.compiler.Validator$ValidateVisitor.visit(Validator.java:868)
 org.apache.jasper.compiler.Node$CustomTag.accept(Node.java:1539)
 org.apache.jasper.compiler.Node$Nodes.visit(Node.java:2376)
 org.apache.jasper.compiler.Node$Visitor.visitBody(Node.java:2428)
 org.apache.jasper.compiler.Node$Visitor.visit(Node.java:2434)
 org.apache.jasper.compiler.Node$Root.accept(Node.java:475)
 org.apache.jasper.compiler.Node$Nodes.visit(Node.java:2376)
 org.apache.jasper.compiler.Validator.validateExDirectives(Validator.java:1787)
 org.apache.jasper.compiler.Compiler.generateJava(Compiler.java:211)
 org.apache.jasper.compiler.Compiler.compile(Compiler.java:360)
 org.apache.jasper.compiler.Compiler.compile(Compiler.java:340)
 org.apache.jasper.compiler.Compiler.compile(Compiler.java:327)
 org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:594)
 org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:316)
 org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:320)
 org.apache.jasper.servlet.JspServlet.service(JspServlet.java:265)
 javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
note The full stack trace of the root cause is available in the Apache Tomcat/7.0.2 logs.

Apache Tomcat/7.0.2

我也尝试过

<fmt:setLocale value="<%= param['local'] %>" scope="session"/>

,但遇到了相同的错误。

I'm trying to set the local in JSP.

I thought I'd be able to do something like:

<fmt:setLocale value="${param['local']}" scope="session"/>

Java's own page on the topic seem to say exactly so much.

However, when I go to execute this, I get:

HTTP Status 500 -

type Exception report

message

description The server encountered an internal error () that prevented it from fulfilling this request.

exception

org.apache.jasper.JasperException: /pages/ResourceBundlesJSTL.jsp(11,0) According to TLD or attribute directive in tag file, attribute value does not accept any expressions
 org.apache.jasper.compiler.DefaultErrorHandler.jspError(DefaultErrorHandler.java:40)
 org.apache.jasper.compiler.ErrorDispatcher.dispatch(ErrorDispatcher.java:407)
 org.apache.jasper.compiler.ErrorDispatcher.jspError(ErrorDispatcher.java:148)
 org.apache.jasper.compiler.Validator$ValidateVisitor.checkXmlAttributes(Validator.java:1232)
 org.apache.jasper.compiler.Validator$ValidateVisitor.visit(Validator.java:868)
 org.apache.jasper.compiler.Node$CustomTag.accept(Node.java:1539)
 org.apache.jasper.compiler.Node$Nodes.visit(Node.java:2376)
 org.apache.jasper.compiler.Node$Visitor.visitBody(Node.java:2428)
 org.apache.jasper.compiler.Node$Visitor.visit(Node.java:2434)
 org.apache.jasper.compiler.Node$Root.accept(Node.java:475)
 org.apache.jasper.compiler.Node$Nodes.visit(Node.java:2376)
 org.apache.jasper.compiler.Validator.validateExDirectives(Validator.java:1787)
 org.apache.jasper.compiler.Compiler.generateJava(Compiler.java:211)
 org.apache.jasper.compiler.Compiler.compile(Compiler.java:360)
 org.apache.jasper.compiler.Compiler.compile(Compiler.java:340)
 org.apache.jasper.compiler.Compiler.compile(Compiler.java:327)
 org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:594)
 org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:316)
 org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:320)
 org.apache.jasper.servlet.JspServlet.service(JspServlet.java:265)
 javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
note The full stack trace of the root cause is available in the Apache Tomcat/7.0.2 logs.

Apache Tomcat/7.0.2

I've also tried

<fmt:setLocale value="<%= param['local'] %>" scope="session"/>

and I get the same error.

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

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

发布评论

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

评论(1

无可置疑 2024-10-09 23:31:50

有几种可能的原因。从你的问题中并不能直接看出它是哪一个。无论如何,我都会在这里提到它们。

  • 如果您的 web.xml 根声明至少不符合 Servlet 2.4(这意味着 JSP 2.0,即运行时标记库支持 EL),则可能会发生这种情况。由于它已经有几年的历史了,并且您正在使用 Servlet 3.0 兼容的 servletcontainer,因此我将其重新声明为 Servlet 3.0。

    <网络应用程序 
        xmlns =“http://java.sun.com/xml/ns/javaee”
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
        版本=“3.0”> 
    
  • 如果 fmt taglib 声明不至少符合 JSTL 1.1(专为 JSP 2.0 设计),也会发生这种情况。确保它看起来像 TLDDOC 所示:

    <%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
    

    (缺少 /jsp 将指示 JSTL 1.0)

  • 如果您的 Webapp/WEB-INF/lib 中实际上有过时的 JSTL 版本,也可能会发生这种情况Tomcat/lib,例如 JSTL 1.0 甚至是旧版 Jakarta。对于 Tomcat 6.x 或更高版本,最好选择 JSTL 1.2 此处 (并且不要忘记删除旧的 standard.jar!)。

There are several possible causes. It's not directly obvious from your question which one it is. I'll mention them all here anyway.

  • This can happen if your web.xml root declaration does not comply at least Servlet 2.4 (which implies JSP 2.0 which is when EL is supported in runtime taglibs). Since that's already several years old and you're using a Servlet 3.0 compatible servletcontainer, I'd redeclare it as Servlet 3.0.

    <web-app 
        xmlns="http://java.sun.com/xml/ns/javaee"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
        version="3.0"> 
    
  • This can also happen if the fmt taglib declaration does not comply at least JSTL 1.1 (which is designed for JSP 2.0). Ensure that it look like as per the TLDDOC:

    <%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
    

    (the absence of /jsp would indicate JSTL 1.0)

  • This can also happen if you actually have an outdated JSTL version in your Webapp/WEB-INF/lib or Tomcat/lib, like JSTL 1.0 or even the legacy Jakarta one. For Tomcat 6.x or newer, it's best to pick JSTL 1.2 here (and don't forget to remove the old standard.jar as well!).

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