为了账号安全,请及时绑定邮箱和手机立即绑定

Context域从web.xml获取数据学习笔记

标签:
JavaScript

web.xml配置文件

<?xml version="1.0" encoding="UTF-8"?><web-app version="3.0"    xmlns="http://java.sun.com/xml/ns/javaee"    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"    xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd">  <context-param>      <param-name>email</param-name>      <param-value>liwen@wen.com</param-value>  </context-param>    <context-param>      <param-name>tel</param-name>      <param-value>13888888888888</param-value>   </context-param>

java文件

import java.io.IOException;import java.io.PrintWriter;import javax.servlet.ServletContext;import javax.servlet.ServletException;import javax.servlet.http.HttpServlet;import javax.servlet.http.HttpServletRequest;import javax.servlet.http.HttpServletResponse;public class webDme extends HttpServlet {    public void doGet(HttpServletRequest request, HttpServletResponse response)            throws ServletException, IOException {        //取得对象         ServletContext context = this.getServletContext();         //从web.xml获取元素        String email =  context.getInitParameter("email");        String tel =  context.getInitParameter("tel");        if(email != null && tel != null)        {        //如果是中文需要加上这个,否则出现乱码            response.setContentType("text/html;charset=UTF-8");            response.getWriter().write("李玟邮箱:"+email+"<br/>");            response.getWriter().write("李玟电话:"+tel+"<br/>");        }    }}

访问路径

http://localhost:8080/day04/webDme


点击查看更多内容
TA 点赞

若觉得本文不错,就分享一下吧!

评论

作者其他优质文章

正在加载中
  • 推荐
  • 评论
  • 收藏
  • 共同学习,写下你的评论
感谢您的支持,我会继续努力的~
扫码打赏,你说多少就多少
赞赏金额会直接到老师账户
支付方式
打开微信扫一扫,即可进行扫码打赏哦
今天注册有机会得

100积分直接送

付费专栏免费学

大额优惠券免费领

立即参与 放弃机会
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号

举报

0/150
提交
取消