码迷,mamicode.com
首页 > Web开发 > 详细

用init-param如何从web.xml中获得参数?

时间:2018-12-13 16:22:57      阅读:443      评论:0      收藏:0      [点我收藏+]

标签:java   who   protected   dex   iter   dog   out   get   load   

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>

详情请见:http://www.mark-to-win.com/index.html?content=Jsp/jspUrl.html&chapter=Jsp/jsp2_web.html#GetParamWithinitparam

用init-param如何从web.xml中获得参数?

标签:java   who   protected   dex   iter   dog   out   get   load   

原文地址:https://www.cnblogs.com/mark-to-win/p/10114138.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!