博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Servlet-获得web.xml配置参数信息
阅读量:7034 次
发布时间:2019-06-28

本文共 1565 字,大约阅读时间需要 5 分钟。

hot3.png

package com.pas.web;import java.io.IOException;import java.io.PrintWriter;import java.util.Enumeration;import javax.servlet.ServletConfig;import javax.servlet.ServletException;import javax.servlet.http.HttpServlet;import javax.servlet.http.HttpServletRequest;import javax.servlet.http.HttpServletResponse;import org.omg.CORBA.Environment;public class ServletConfigTest extends HttpServlet {		public void doGet(HttpServletRequest request, HttpServletResponse response)			throws ServletException, IOException {		response.setCharacterEncoding(this.getServletConfig().getInitParameter("encoding"));		response.getWriter().println("你好世界aaaa");				Enumeration
en= this.getServletConfig().getInitParameterNames(); String lineSeparator = System.getProperty("line.separator", "/n"); while(en.hasMoreElements()) { response.getWriter().println(en.nextElement()+lineSeparator); } } public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { this.doGet(request, response); }}

 

Web.XML

This is the description of my J2EE component
This is the display name of my J2EE component
ServletConfigTest
com.pas.web.ServletConfigTest
encoding
gb2312
    
context_param
    
value3
 

此类设置对应web应用全局访问:

this.getServletContext().getInitParameter("context_param")

转载于:https://my.oschina.net/u/1246663/blog/165505

你可能感兴趣的文章
linux 下借助CRT 使用sz rz 进行上传和下载文件
查看>>
ftp服务结合pam_mysql 使用错误
查看>>
匿名用户上传文件
查看>>
SyntaxHighlighter使用方法
查看>>
细聊MySQL之基本安装与启动
查看>>
揭开Socket编程的面纱
查看>>
编译安装基于NFS+LAMP+DNS+iptables+SELinux构建安全稳定的web服务器(一)
查看>>
SQL中什么叫模式
查看>>
Zabbix完整监控
查看>>
数据绑定(一)
查看>>
我的友情链接
查看>>
我的友情链接
查看>>
文本处理“三剑客”之SED"
查看>>
find应用示例
查看>>
Kmail身份验证组件
查看>>
为什么很多招聘信息都要求三年以上的工作经验?
查看>>
拷贝构造函数为何传入引用?
查看>>
at命令及服务
查看>>
sqlserver无法在数据库上放置锁
查看>>
完全背包问题
查看>>