Tomcat :在上下文参数名称中使用双引号字符
Tomcat : using double-quote character in a context parameter name
我找不到在我想在部署描述符文件中声明的上下文参数名称中使用双引号字符的正确语法。
这里是web.xml中的参数定义:
<context-param>
<param-name>Catalina:type=GlobalRequestProcessor,name=\"http-nio-8080\"</param-name>
<param-value>requestCount</param-value>
</context-param>
以下 JSP 代码:
<%@ page import="java.util.*,javax.management.*"%>
JMX testing
<%
Enumeration ipn = application.getInitParameterNames();
String ipnName = "";
while(ipn.hasMoreElements()) {
ipnName = (String)ipn.nextElement();
ObjectName on = new ObjectName( ipnName );
}
%>
触发此异常:
HTTP Status 500 – Internal
Server Errorh1
{font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:22px;}
h2
{font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:16px;}
h3
{font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:14px;}
body
{font-family:Tahoma,Arial,sans-serif;color:black;background-color:white;}
b
{font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;} p
{font-family:Tahoma,Arial,sans-serif;background:white;color:black;font-size:12px;}
a {color:black;} a.name {color:black;} .line
{height:1px;background-color:#525D76;border:none;}
HTTP
Status 500 – Internal Server Error
Type Exception Report
Message
javax.servlet.ServletException:
javax.management.MalformedObjectNameException: Invalid character
'"' in value part of property
Description
The server encountered an unexpected condition that prevented it from
fulfilling the
request.
Exception
org.apache.jasper.JasperException:
javax.servlet.ServletException:
javax.management.MalformedObjectNameException: Invalid character
'"' in value part of property
org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:598)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:499)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:386)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:330)
javax.servlet.http.HttpServlet.service(HttpServlet.java:742)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
Root Cause
javax.servlet.ServletException:
javax.management.MalformedObjectNameException: Invalid character
'"' in value part of property
org.apache.jasper.runtime.PageContextImpl.doHandlePageException(PageContextImpl.java:909)
org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:838)
org.apache.jsp.ko_jsp._jspService(ko_jsp.java:138)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
javax.servlet.http.HttpServlet.service(HttpServlet.java:742)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:476)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:386)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:330)
javax.servlet.http.HttpServlet.service(HttpServlet.java:742)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
Root
Cause
javax.management.MalformedObjectNameException:
Invalid character '"' in value part of property
java.management/javax.management.ObjectName.construct(ObjectName.java:621)
java.management/javax.management.ObjectName.<init>(ObjectName.java:1406)
org.apache.jsp.ko_jsp._jspService(ko_jsp.java:122)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
javax.servlet.http.HttpServlet.service(HttpServlet.java:742)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:476)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:386)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:330)
javax.servlet.http.HttpServlet.service(HttpServlet.java:742)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
我尝试更改 JASPER strictQuoteEscaping 值和不同的语法但没有效果。我是 运行 Tomcat 8.5.40 和 Java 9 u181
顺便说一句,直接调用这个 JMX 运行良好:
<%@ page import="java.util.*,javax.management.*"%>
JMX testing
<%
ObjectName on = new ObjectName("Catalina:type=GlobalRequestProcessor,name=\"http-nio-8080\"");
%>
我遗漏了什么明显的东西吗?
如果 "
字符位于标签之间,则无需转义。基本上 <param-name>
标签之间的字符串:
<param-name>Catalina:type=GlobalRequestProcessor,name=\"http-nio-8080\"</param-name>
等于字符串(注意三个back-slashes):
Catalina:type=GlobalRequestProcessor,name=\\"http-nio-8080\\"
因此,在 web.xml 中指定对象名称时,只需按照在纸上书写的方式进行(即不带反斜杠):
<param-name>Catalina:type=GlobalRequestProcessor,name="http-nio-8080"</param-name>
更新(关于评论中的第二个问题)
This doesn't work, this time the exception is
org.apache.jasper.JasperException: javax.servlet.ServletException:
javax.management.MalformedObjectNameException: Key properties cannot
be empty Did you try your suggestion on a Tomcat with JMX correctly
configured and enabled ?
key properties
是冒号后的 key-value 对。在您的示例中,您有两个键:
- type=GlobalRequestProcessor
- 姓名="http-nio-8080"
所以唯一的解释就是这个异常是因为:
- 使用另一个构造函数(不太可能,您在问题中的代码使用了正确的构造函数)
- 您的上下文参数比显示的多,其中一些在
:
之后没有任何内容。请注意,您正在遍历所有上下文参数,其中一些可能不是对象名称:while(ipn.hasMoreElements())
您只需打印其名称即可找到导致问题的上下文参数:
<%
Enumeration ipn = application.getInitParameterNames();
String ipnName;
while (ipn.hasMoreElements()) {
ipnName = (String) ipn.nextElement();
try {
ObjectName on = new ObjectName(ipnName);
out.println("<br>Good param: " + ipnName);
}catch (Exception e){
out.println("<br>Bad param: " + ipnName);
}
}
%>
我找不到在我想在部署描述符文件中声明的上下文参数名称中使用双引号字符的正确语法。
这里是web.xml中的参数定义:
<context-param>
<param-name>Catalina:type=GlobalRequestProcessor,name=\"http-nio-8080\"</param-name>
<param-value>requestCount</param-value>
</context-param>
以下 JSP 代码:
<%@ page import="java.util.*,javax.management.*"%>
JMX testing
<%
Enumeration ipn = application.getInitParameterNames();
String ipnName = "";
while(ipn.hasMoreElements()) {
ipnName = (String)ipn.nextElement();
ObjectName on = new ObjectName( ipnName );
}
%>
触发此异常:
HTTP Status 500 – Internal Server Errorh1 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:22px;} h2 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:16px;} h3 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:14px;} body {font-family:Tahoma,Arial,sans-serif;color:black;background-color:white;} b {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;} p {font-family:Tahoma,Arial,sans-serif;background:white;color:black;font-size:12px;} a {color:black;} a.name {color:black;} .line {height:1px;background-color:#525D76;border:none;}
HTTP Status 500 – Internal Server Error
Type Exception Report
Message javax.servlet.ServletException: javax.management.MalformedObjectNameException: Invalid character '"' in value part of property
Description The server encountered an unexpected condition that prevented it from fulfilling the request.
Exception
org.apache.jasper.JasperException: javax.servlet.ServletException: javax.management.MalformedObjectNameException: Invalid character '"' in value part of property org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:598) org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:499) org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:386) org.apache.jasper.servlet.JspServlet.service(JspServlet.java:330) javax.servlet.http.HttpServlet.service(HttpServlet.java:742) org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)Root Cause
javax.servlet.ServletException: javax.management.MalformedObjectNameException: Invalid character '"' in value part of property org.apache.jasper.runtime.PageContextImpl.doHandlePageException(PageContextImpl.java:909) org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:838) org.apache.jsp.ko_jsp._jspService(ko_jsp.java:138) org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70) javax.servlet.http.HttpServlet.service(HttpServlet.java:742) org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:476) org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:386) org.apache.jasper.servlet.JspServlet.service(JspServlet.java:330) javax.servlet.http.HttpServlet.service(HttpServlet.java:742) org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)Root Cause
javax.management.MalformedObjectNameException: Invalid character '"' in value part of property java.management/javax.management.ObjectName.construct(ObjectName.java:621) java.management/javax.management.ObjectName.<init>(ObjectName.java:1406) org.apache.jsp.ko_jsp._jspService(ko_jsp.java:122) org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70) javax.servlet.http.HttpServlet.service(HttpServlet.java:742) org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:476) org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:386) org.apache.jasper.servlet.JspServlet.service(JspServlet.java:330) javax.servlet.http.HttpServlet.service(HttpServlet.java:742) org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
我尝试更改 JASPER strictQuoteEscaping 值和不同的语法但没有效果。我是 运行 Tomcat 8.5.40 和 Java 9 u181
顺便说一句,直接调用这个 JMX 运行良好:
<%@ page import="java.util.*,javax.management.*"%>
JMX testing
<%
ObjectName on = new ObjectName("Catalina:type=GlobalRequestProcessor,name=\"http-nio-8080\"");
%>
我遗漏了什么明显的东西吗?
如果 "
字符位于标签之间,则无需转义。基本上 <param-name>
标签之间的字符串:
<param-name>Catalina:type=GlobalRequestProcessor,name=\"http-nio-8080\"</param-name>
等于字符串(注意三个back-slashes):
Catalina:type=GlobalRequestProcessor,name=\\"http-nio-8080\\"
因此,在 web.xml 中指定对象名称时,只需按照在纸上书写的方式进行(即不带反斜杠):
<param-name>Catalina:type=GlobalRequestProcessor,name="http-nio-8080"</param-name>
更新(关于评论中的第二个问题)
This doesn't work, this time the exception is org.apache.jasper.JasperException: javax.servlet.ServletException: javax.management.MalformedObjectNameException: Key properties cannot be empty Did you try your suggestion on a Tomcat with JMX correctly configured and enabled ?
key properties
是冒号后的 key-value 对。在您的示例中,您有两个键:
- type=GlobalRequestProcessor
- 姓名="http-nio-8080"
所以唯一的解释就是这个异常是因为:
- 使用另一个构造函数(不太可能,您在问题中的代码使用了正确的构造函数)
- 您的上下文参数比显示的多,其中一些在
:
之后没有任何内容。请注意,您正在遍历所有上下文参数,其中一些可能不是对象名称:while(ipn.hasMoreElements())
您只需打印其名称即可找到导致问题的上下文参数:
<%
Enumeration ipn = application.getInitParameterNames();
String ipnName;
while (ipn.hasMoreElements()) {
ipnName = (String) ipn.nextElement();
try {
ObjectName on = new ObjectName(ipnName);
out.println("<br>Good param: " + ipnName);
}catch (Exception e){
out.println("<br>Bad param: " + ipnName);
}
}
%>