[英]Get initialization parameter from the web.xml file. in Eclipse and Tomcat
I am following this tutorial http://www.javatpoint.com/config-implicit-object 我正在按照本教程http://www.javatpoint.com/config-implicit-object
This tutorial uses an file web.xml without a servelet and fill in the variables of the file "welcome.jsp" with the data of the file "web.xml" I put all files in the same folder of Eclipse called "WebContent", but the program don't work. 本教程使用不带Servet的文件web.xml,并用文件“ web.xml”的数据填充文件“ welcome.jsp”的变量,我将所有文件都放在Eclipse的同一文件夹中,称为“ WebContent”,但该程序不起作用。 I am a newbie in Eclipse and JSP 我是Eclipse和JSP的新手
WebContent/index.html 的WebContent / index.html的
<form action="welcome">
<input type="text" name="uname">
<input type="submit" value="go"><br/>
</form>
WebContent/web.xml 的WebContent / web.xml文件
<web-app>
<servlet>
<servlet-name>sonoojaiswal</servlet-name>
<jsp-file>/welcome.jsp</jsp-file>
<init-param>
<param-name>dname</param-name>
<param-value>sun.jdbc.odbc.JdbcOdbcDriver</param-value>
</init-param>
</servlet>
<servlet-mapping>
<servlet-name>sonoojaiswal</servlet-name>
<url-pattern>/welcome</url-pattern>
</servlet-mapping>
</web-app>
WebContent/welcome.jsp 的WebContent /的welcome.jsp
<%
out.print("Welcome "+request.getParameter("uname"));
String driver=config.getInitParameter("dname");
out.print("driver name is="+driver);
%>
You have to put web.xml
into the WEB-INF
directory. 您必须将web.xml
放入WEB-INF
目录。 That is where the servlet container expects it, otherwise it has no effect. 这就是servlet容器所期望的,否则无效。 Putting it into WEB-INF
also has the "side-effect" of not making the file accessible to users for download through their browser (which would be bad, as it can contain sensitive configuration information). 将其放入WEB-INF
还具有“副作用”,即使用户无法通过其浏览器下载该文件(这很不好,因为它可能包含敏感的配置信息)。
So the path should be WebContent/WEB-INF/web.xml
. 因此,路径应为WebContent/WEB-INF/web.xml
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.