在以下Web应用程序结构中,我试图将init.xml和context参数从web.xml页面放到jsp页面而不使用servlet。
的index.html:
<html>
<head>
<meta charset="ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
<form action="action" method="get">
<a href="home.jsp">clik here</a></form>
</body>
</html>
的web.xml:
<webapp>
<context-param>
<param-name>per1</param-name>
<param-value>val1</param-value>
</context-param>
<welcome-file>
index.jsp</welcome-file>
<servlet>
<servlet-name>abc</servlet-name>
<jsp-file>home.jsp</jsp-file>
<init-param>
<description>This is an init parameter example</description>
<param-name>InitParam</param-name>
<param-value>init param value</param-value>
</init-param>
</servlet>
<servlet-mapping>
<servlet-name>abc</servlet-name>
<url-pattern>action</url-pattern>
</servlet-mapping>
针对home.jsp:
<html>
<body>
<%= application.getInitParameter("per1")%>
<%= config.getInitParameter("InitParam") %>
${initParam.per1)
</body>
</html>
但我无法在我的jsp页面中访问这些init和context参数。
null null
请让我知道我哪里出错了
由于
答案 0 :(得分:0)
您的URL
模式和jsp
名称似乎不匹配。更改web.xml
<servlet-name>abc</servlet-name>
<jsp-file>/home.jsp</jsp-file>
<init-param>
<description>This is an init parameter example</description>
<param-name>InitParam</param-name>
<param-value>init param value</param-value>
</init-param>
</servlet>
<servlet-mapping>
<servlet-name>abc</servlet-name>
<url-pattern>/home.jsp</url-pattern>
</servlet-mapping>