JSP 初始化参数:

tomcat启动的时候就会执行那个函数;

xml:

<?xml version="1.0" encoding="UTF-8"?>
<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" id="WebApp_ID"
version="3.0">
<display-name>TestBootWeb</display-name>
<servlet>
<servlet-name>index007</servlet-name>
<jsp-file>/index007.jsp</jsp-file>
<init-param>
<param-name>email</param-name>
<param-value>s@s.com</param-value>
</init-param>
</servlet>
<servlet-mapping>
<servlet-name>index007</servlet-name>
<url-pattern>/index007.jsp</url-pattern>
<!-- 写成/index007.jsp的话,竟然index007.jsp和index0071.jsp都可以访问,而且是两个实例,但是获取初始化参数的时候有问题 -->
</servlet-mapping>
<jsp-config>
<jsp-property-group>
<url-pattern>/index006.jsp</url-pattern>
<scripting-invalid>true</scripting-invalid>
</jsp-property-group>
</jsp-config>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
</web-app>

jsp:

<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + path + "/";
%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>007index</title>
</head>
<body>
cnt is :<%=++cnt%>
<hr>
<%!int cnt = 0;%>
<%!
public void jspInit(){
ServletConfig config = getServletConfig();
String s = config.getInitParameter("email");
System.out.println("s is :"+s);
}
%>
</body>
</html>

生成的java:

/*
* Generated by the Jasper component of Apache Tomcat
* Version: Apache Tomcat/7.0.35
* Generated at: 2015-10-20 01:19:21 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; import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.jsp.*;
import java.util.*; public final class index007_jsp extends org.apache.jasper.runtime.HttpJspBase
implements org.apache.jasper.runtime.JspSourceDependent { int cnt = 0; public void jspInit(){
ServletConfig config = getServletConfig();
String s = config.getInitParameter("email");
System.out.println("s is :"+s);
} 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'); String path = request.getContextPath();
String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + path + "/"; out.write("\r\n");
out.write("<!DOCTYPE html>\r\n");
out.write("<html>\r\n");
out.write("<head>\r\n");
out.write("<meta charset=\"UTF-8\">\r\n");
out.write("<title>007index</title>\r\n");
out.write("</head>\r\n");
out.write("<body>\r\n");
out.write("\tcnt is :");
out.print(++cnt);
out.write("\r\n");
out.write("\t<hr>\r\n");
out.write("\t");
out.write('\r');
out.write('\n');
out.write(' ');
out.write("\r\n");
out.write("</body>\r\n");
out.write("</html>\r\n");
} 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);
}
}
}

JSP 初始化参数的更多相关文章

  1. Spring MVC初始化参数绑定

    初始化参数绑定与类型转换很类似,初始化绑定时,主要是参数类型 ---单日期 在处理器类中配置绑定方法  使用@InitBinder注解 在这里首先注册一个用户编辑器 参数一为目标类型   proper ...

  2. SpringMVC初始化参数绑定--日期格式

    一.初始化参数绑定[一种日期格式] 配置步骤: ①:在applicationcontext.xml中只需要配置一个包扫描器即可 <!-- 包扫描器 --> <context:comp ...

  3. SpringMvc中初始化参数绑定

    初始化参数绑定与类型转换很类似,初始化绑定时,主要是参数类型 ---单日期 在处理器类中配置绑定方法  使用@InitBinder注解 在这里首先注册一个用户编辑器 参数一为目标类型   proper ...

  4. web.xml 中以编码方式添加filter并设置初始化参数AbstractAnnotationConfigDispatchServletInitializer

    web.xml中配置filter <?xml version="1.0" encoding="UTF-8"?> <web-app versio ...

  5. springmvc的初始化参数绑定

    一.springmvc的初始化参数绑定 此种和我们之前说的类型转换非常相似,可以看作是一种类型转换 在初始化参数绑定时  重要的是参数类型 -------------------单日期的绑定 二. 配 ...

  6. Qt中新建类构造函数的初始化参数列表

    使用Qt-creator自动生成一个窗体应用程序时会自动创建一个新的类,我的程序中名为MyDialog,类的定义为: #ifndef MYDIALOG_H #define MYDIALOG_H #in ...

  7. JavaWeb---通过ServletConfig获取Servlet的初始化参数

    package com.zyz; import javax.servlet.ServletConfig; import javax.servlet.ServletException; import j ...

  8. web.xml的初始化参数

    web.xml的初始化参数 ---------首先声明,这里所介绍的是web中context-param,init-param参数的初始化配置---------- ------------------ ...

  9. RCU-数据库初始化参数

    C:\Windows\System32>sqlplus sys/As123456 as sysdba SQL> show parameter processes; SQL> shut ...

随机推荐

  1. Ant自动构建

    Ant+jenkins+tomcat <project name="buildWar" default="clean"> <property ...

  2. 基于Verilog HDL 各种实验

    菜鸟做的的小实验链接汇总:           1.基于Verilog HDL 的数字时钟设计 2.乘法器 3.触发器(基本的SR触发器.同步触发器.D触发器) 4.基于Verilog HDL的ADC ...

  3. 杀死进程kill和fuser

    1 kill -9 id 2   不行的话使用    fuser -k -SIGHUP /opt/bre/cookiemapping/wsapi/123 fuser有一个特别的用法在于它可以一次杀死那 ...

  4. 关于easyUI的datagrid的编辑功能时的问题

    编辑时,如果form中包含了id输入域,会发送一个{id,id}这样的字符串到服务端,因为javascript的function edit(){}逻辑中,已经拿到Id提交了.所以,编辑和添加功能共用的 ...

  5. android init.rc 语法分析

    此文来自于对http://source.android.com/porting/index.html中bring up段的简译.其中有一处与源码的 system/core/init/readme.tx ...

  6. SqlServer拆分列

    SELECT TOP 1000 substring([a],0,CHARINDEX('/',a)) as low,substring([a],CHARINDEX('/',a)+1,len([a])-C ...

  7. Hibernate查询之API查询

    Hibernate在检索数据上,可以使用SQL.HQL和官方API进行查询,本人主要利用API进行相关查询的小demo. 话不多少直接上demo. demo1:基本查询 /** * 默认不加任何条件的 ...

  8. 关于LCD以及BMP和RGB565

    源: 关于LCD以及BMP和RGB565

  9. dedecms标签使用

    关键描述调用标签: <meta name="keywords" content="{dede:field name='keywords'/}">&l ...

  10. 3个人一起写的EI论文可以检索到啦~ --> Exploring the use of a 3D Virtual Environment in Chinese Cultural Transmission

    <a href='http://www.engineeringvillage.com/blog/document.url?mid=cpx_10ed754f14b5b7381b6M764b1017 ...