如何配置servlet初始化参数和jsp初始化参数。
1个回答
展开全部
servlet初始化参数:
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee
http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
<web-app>
<servlet>
<servlet-name></servlet-name>
<servlet-class></servlet-class>
<init-param>
<param-name></param-name>
<param-value></param-value>
</init-param>
</servlet>
<servlet-mapping>
<servlet-name></servlet-name>
<url-pattern></url-pattern>
</servlet-mapping>
</web-app>
-------------------------------------------------------
jsp初始化参数:
<%@ page import="java.util.*" %>
<%!
ServletConfig cfg =null;
public void jspInit(){
ServletConfig cfg=getServletConfig();
for (Enumeration e=cfg.getInitParameterNames(); e.hasMoreElements();) {
String name=(String)e.nextElement();
String value = cfg.getInitParameter(name);
System.out.println(name+"="+value);
}
}
%>
<html>
<body>
<h1>
See the console for the init params accessible by this JSP page
</h1>
</body>
</html>
===================================================
初始化参数在服务器上设置的,参考JSWDK里设置
# $Id: servlets.properties,v 1.3.2.2 1999/07/27 00:52:13 mandar Exp $
# Define servlets here
# <servletname>.code=<servletclass>
# <servletname>.initparams=<name=value>,<name=value>
#snoop.code=SnoopServlet
#snoop.initparams=initarg1=foo,initarg2=bar
cookie.code=CookieExample
cookie.initparams=foo
jsp.code=com.sun.jsp.runtime.JspServlet
jsp.initparams=keepgenerated=true,myparam1=val1,myparam2=val2
jts.code=servletToJsp
jts.initparams=foo
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee
http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
<web-app>
<servlet>
<servlet-name></servlet-name>
<servlet-class></servlet-class>
<init-param>
<param-name></param-name>
<param-value></param-value>
</init-param>
</servlet>
<servlet-mapping>
<servlet-name></servlet-name>
<url-pattern></url-pattern>
</servlet-mapping>
</web-app>
-------------------------------------------------------
jsp初始化参数:
<%@ page import="java.util.*" %>
<%!
ServletConfig cfg =null;
public void jspInit(){
ServletConfig cfg=getServletConfig();
for (Enumeration e=cfg.getInitParameterNames(); e.hasMoreElements();) {
String name=(String)e.nextElement();
String value = cfg.getInitParameter(name);
System.out.println(name+"="+value);
}
}
%>
<html>
<body>
<h1>
See the console for the init params accessible by this JSP page
</h1>
</body>
</html>
===================================================
初始化参数在服务器上设置的,参考JSWDK里设置
# $Id: servlets.properties,v 1.3.2.2 1999/07/27 00:52:13 mandar Exp $
# Define servlets here
# <servletname>.code=<servletclass>
# <servletname>.initparams=<name=value>,<name=value>
#snoop.code=SnoopServlet
#snoop.initparams=initarg1=foo,initarg2=bar
cookie.code=CookieExample
cookie.initparams=foo
jsp.code=com.sun.jsp.runtime.JspServlet
jsp.initparams=keepgenerated=true,myparam1=val1,myparam2=val2
jts.code=servletToJsp
jts.initparams=foo
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询