servletContext应用

 

配置初始化参数

<context-param>
        <param-name>url</param-name>
        <param-value>woshishabi:;</param-value>
    </context-param>

获取并输出

复制代码
public class ServletDemo03 extends HelloServlet {

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        ServletContext context=this.getServletContext();
        String url=context.getInitParameter("url");
        resp.getWriter().println(url);

    }
复制代码

public class ServletDemo04 extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        ServletContext context=this.getServletContext();
        context.getRequestDispatcher("/gp").forward(req,resp);//请求转发
    }
}

请求转发和重定向

 

 

 

Properties类可以和文件输入流配合使用,

load(文件流)

 

 

posted on   大风吹过12138  阅读(17)  评论(0编辑  收藏  举报

相关博文:
阅读排行:
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· SQL Server 2025 AI相关能力初探
· AI编程工具终极对决:字节Trae VS Cursor,谁才是开发者新宠?
· 开源Multi-agent AI智能体框架aevatar.ai,欢迎大家贡献代码
· Manus重磅发布:全球首款通用AI代理技术深度解析与实战指南
点击右上角即可分享
微信分享提示