用init-param如何从web.xml中获得参数?
Posted mark-to-win
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了用init-param如何从web.xml中获得参数?相关的知识,希望对你有一定的参考价值。
1.用init-param获取:(视频下载) (全部书籍)
例:1.1.1
ServletHello1.java:
package com;
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public class ServletHello1 extends HttpServlet {
protected void doGet(HttpServletRequest request,HttpServletResponse response) throws ServletException, IOException {
String salary = getInitParameter("zhangsan");
System.out.println("salary is "+salary);
}
}
在web.xml中加入:
<servlet>
<servlet-name>ServletHello1</servlet-name>
<servlet-class>com.ServletHello1</servlet-class>
<init-param>
<param-name>zhangsan</param-name>
<param-value>1000</param-value>
</init-param>
</servlet>
<servlet-mapping>
<servlet-name>ServletHello1</servlet-name>
以上是关于用init-param如何从web.xml中获得参数?的主要内容,如果未能解决你的问题,请参考以下文章
web.xml中在Servlet中获取context-param和init-param内的参数
web.xml配置参数context-param和init-param的区别
传值:web.xml传递参数 即在Servlet中获取web.xml里的值
web.xml文件报错:cvc-complex-type.2.4.a: Invalid content was found starting with element 'init-param&