当前位置 : 主页 > 编程语言 > java >

Scripting elements ( <%!, <jsp:declaration, <%=, <jsp:expression, 错误的解决方

来源:互联网 收集:自由互联 发布时间:2021-06-25
%@ page contentType="text/html;charset=UTF-8" %%session.setAttribute("pageContext", "it315");%输出表达式\\${pageContext}的值:br/${pageContext} 【web.xml】错误地在 web.xml中禁用了 jsp脚本元素 jsp-configjsp-property-gro
<%@ page contentType="text/html;charset=UTF-8" %>
<%
	session.setAttribute("pageContext", "it315");
%>
输出表达式\\${pageContext}的值:<br/>
${pageContext}

【web.xml】错误地在 web.xml中禁用了 jsp脚本元素

<jsp-config>
	<jsp-property-group>
		<url-pattern>*.jsp</url-pattern>
		<page-encoding>UTF-8</page-encoding>
	</jsp-property-group>
	
	 <!-- 忽略EL表达式 -->
	<jsp-property-group>
		<url-pattern>*.jsp</url-pattern>
		<el-ignored>true</el-ignored>
	</jsp-property-group>
	
	<!-- 禁用 jsp 脚本元素 -->
	<jsp-property-group>
		<url-pattern>*.jsp</url-pattern>
		<scripting-invalid>true</scripting-invalid>
	</jsp-property-group>

  </jsp-config>

【报错信息如下】


【解决方法】 在web.xml中 把 禁用 jsp 脚本元素的配置信息删除即可;

【访问效果如下】


【web.xml 源码】

<?xml version="1.0" encoding="ISO-8859-1"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" version="3.0">
  <servlet>
    <servlet-name>default</servlet-name>
    <servlet-class>org.apache.catalina.servlets.DefaultServlet</servlet-class>
    <init-param>
      <param-name>debug</param-name>
      <param-value>0</param-value>
    </init-param>
    <init-param>
      <param-name>listings</param-name>
      <param-value>false</param-value>
    </init-param>
    <load-on-startup>1</load-on-startup>
  </servlet>
   <servlet-mapping>
    <servlet-name>default</servlet-name>
    <url-pattern>/</url-pattern>
  </servlet-mapping>
  
  <servlet>
    <servlet-name>jsp</servlet-name>
    <servlet-class>org.apache.jasper.servlet.JspServlet</servlet-class>
    <init-param>
      <param-name>fork</param-name>
      <param-value>false</param-value>
    </init-param>
    <init-param>
      <param-name>xpoweredBy</param-name>
      <param-value>false</param-value>
    </init-param>
    <load-on-startup>3</load-on-startup>
  </servlet>
  <servlet-mapping>
    <servlet-name>jsp</servlet-name>
    <url-pattern>*.jsp</url-pattern>
    <url-pattern>*.jspx</url-pattern>
  </servlet-mapping>
  
  <mime-mapping>
    <extension>abs</extension>
    <mime-type>audio/x-mpeg</mime-type>
  </mime-mapping>
  
  <jsp-config>
	<jsp-property-group>
		<url-pattern>*.jsp</url-pattern>
		<page-encoding>UTF-8</page-encoding>
	</jsp-property-group>
	
	 <!-- 忽略EL表达式 
	<jsp-property-group>
		<url-pattern>*.jsp</url-pattern>
		<el-ignored>true</el-ignored>
	</jsp-property-group>
	-->
	<!-- 禁用 jsp 脚本元素 
	<jsp-property-group>
		<url-pattern>*.jsp</url-pattern>
		<scripting-invalid>true</scripting-invalid>
	</jsp-property-group>
-->

  </jsp-config>
  
  <!-- 
    <filter>
	 	<filter-name>FirstFilter</filter-name>
		<filter-class>com.asite2.chapter2.ex2_3.FirstFilter</filter-class>
		<init-param>
			<param-name>encoding</param-name>
			<param-value>UTF-8</param-value>
		</init-param>
	</filter>
	<filter-mapping>
		<filter-name>FirstFilter</filter-name>
		<url-pattern>/*</url-pattern>
	</filter-mapping>
	<filter-mapping>
		<filter-name>FirstFilter</filter-name>
		<servlet-name>default</servlet-name>	
	</filter-mapping>
	<filter-mapping>
		<filter-name>FirstFilter</filter-name>
		<url-pattern>/test.html</url-pattern>	
	</filter-mapping>
	
	<filter>
	 	<filter-name>SecondFilter</filter-name>
		<filter-class>com.asite2.chapter2.ex2_3.SecondFilter</filter-class>
		<init-param>
			<param-name>encoding</param-name>
			<param-value>UTF-8</param-value>
		</init-param>
	</filter>
	<filter-mapping>
		<filter-name>SecondFilter</filter-name>
		<url-pattern>/*</url-pattern>
	</filter-mapping>
	 -->
	
	<!--  
	<listener>
		<listener-class>ex3_1.MyListener</listener-class>
	</listener>
	 -->
	 
	 <!-- 
	<listener>
		<listener-class>ex3_4.CountListener</listener-class>
	</listener>
	
	<listener>
		<listener-class>ex3_7.MyAttributeListener</listener-class>
	</listener>
	 -->
	<session-config>
		<session-timeout>1</session-timeout>
	</session-config>
	
</web-app>
【implicitObj.jsp】
<%@ page contentType="text/html;charset=UTF-8" %>
<%
	session.setAttribute("pageContext", "it315");
%>
输出表达式\${pageContext}的值:<br/>
${pageContext}
【implicitObj_jsp.java】
/*
 * Generated by the Jasper component of Apache Tomcat
 * Version: Apache Tomcat/7.0.35
 * Generated at: 2018-02-08 16:45:35 UTC
 * Note: The last modified time of this file was set to
 *       the last modified time of the source file after
 *       generation to assist with modification tracking.
 */
package org.apache.jsp.chapter5.ex5_005f4;

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.jsp.*;

public final class implicitObj_jsp extends org.apache.jasper.runtime.HttpJspBase
    implements org.apache.jasper.runtime.JspSourceDependent {

  private static final javax.servlet.jsp.JspFactory _jspxFactory =
          javax.servlet.jsp.JspFactory.getDefaultFactory();

  private static java.util.Map<java.lang.String,java.lang.Long> _jspx_dependants;

  private javax.el.ExpressionFactory _el_expressionfactory;
  private org.apache.tomcat.InstanceManager _jsp_instancemanager;

  public java.util.Map<java.lang.String,java.lang.Long> getDependants() {
    return _jspx_dependants;
  }

  public void _jspInit() {
    _el_expressionfactory = _jspxFactory.getJspApplicationContext(getServletConfig().getServletContext()).getExpressionFactory();
    _jsp_instancemanager = org.apache.jasper.runtime.InstanceManagerFactory.getInstanceManager(getServletConfig());
  }

  public void _jspDestroy() {
  }

  public void _jspService(final javax.servlet.http.HttpServletRequest request, final javax.servlet.http.HttpServletResponse response)
        throws java.io.IOException, javax.servlet.ServletException {

    final javax.servlet.jsp.PageContext pageContext;
    javax.servlet.http.HttpSession session = null;
    final javax.servlet.ServletContext application;
    final javax.servlet.ServletConfig config;
    javax.servlet.jsp.JspWriter out = null;
    final java.lang.Object page = this;
    javax.servlet.jsp.JspWriter _jspx_out = null;
    javax.servlet.jsp.PageContext _jspx_page_context = null;


    try {
      response.setContentType("text/html;charset=UTF-8");
      pageContext = _jspxFactory.getPageContext(this, request, response,
      			null, true, 8192, true);
      _jspx_page_context = pageContext;
      application = pageContext.getServletContext();
      config = pageContext.getServletConfig();
      session = pageContext.getSession();
      out = pageContext.getOut();
      _jspx_out = out;

      out.write('\r');
      out.write('\n');

	session.setAttribute("pageContext", "it315");

      out.write("\r\n");
      out.write("输出表达式${pageContext}的值:<br/>\r\n");
      out.write((java.lang.String) org.apache.jasper.runtime.PageContextImpl.proprietaryEvaluate("${pageContext}", java.lang.String.class, (javax.servlet.jsp.PageContext)_jspx_page_context, null, false));
      out.write(' ');
    } catch (java.lang.Throwable t) {
      if (!(t instanceof javax.servlet.jsp.SkipPageException)){
        out = _jspx_out;
        if (out != null && out.getBufferSize() != 0)
          try { out.clearBuffer(); } catch (java.io.IOException e) {}
        if (_jspx_page_context != null) _jspx_page_context.handlePageException(t);
        else throw new ServletException(t);
      }
    } finally {
      _jspxFactory.releasePageContext(_jspx_page_context);
    }
  }
}
网友评论