zoukankan      html  css  js  c++  java
  • EL表达式 requestScope initParam用法

    EL表达式 requestScope initParam用法:

    servlet:

    package com.stono.servlet;
    import java.io.IOException;
    import javax.servlet.RequestDispatcher;
    import javax.servlet.ServletException;
    import javax.servlet.http.HttpServlet;
    import javax.servlet.http.HttpServletRequest;
    import javax.servlet.http.HttpServletResponse;
    public class TestServlet7 extends HttpServlet {
        private static final long serialVersionUID = 1L;
        @Override
        protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
            req.setAttribute("foo.person", "personFoo");
            RequestDispatcher dispatcher = req.getRequestDispatcher("index045.jsp");
            dispatcher.forward(req, resp);
        }
    }

    jsp:

    <%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
    <%
        String path = request.getContextPath();
        String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + path + "/";
    %>
    <!DOCTYPE html>
    <html>
    <head>
    <meta charset="UTF-8">
    <title>045index</title>
    </head>
    <body>
        ${requestScope["foo.person"] }
        <hr>
        ${initParam.email }
        <hr>
        ${cookie }
    </body>
    </html>

    web.xml:

    <?xml version="1.0" encoding="UTF-8"?>
    <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee 
        http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" id="WebApp_ID"
        version="3.0">
        <display-name>TestBootWeb</display-name>
        <servlet>
            <servlet-name>test7</servlet-name>
            <servlet-class>com.stono.servlet.TestServlet7</servlet-class>
        </servlet>
        <servlet-mapping>
            <servlet-name>test7</servlet-name>
            <url-pattern>/test7.do</url-pattern>
        </servlet-mapping>
        <context-param>
            <param-name>email</param-name>
            <param-value>a@b.c</param-value>
        </context-param>
        <jsp-config>
            <jsp-property-group>
                <url-pattern>*.jsp</url-pattern>
                <el-ignored>false</el-ignored>
            </jsp-property-group>
        </jsp-config>
        <welcome-file-list>
            <welcome-file>index.jsp</welcome-file>
        </welcome-file-list>
    </web-app>
  • 相关阅读:
    Uva 10779 collector's problem
    poj 2728 最优比率树(最小生成树问题)
    LA 3126 二分图匹配 最小路径覆盖
    poj 1149 最大流构图
    Step By Step(Java XML篇)
    Step By Step(Java 输入输出篇)
    Step By Step(Java 集合篇)
    Step By Step(Java 线程篇)
    Step By Step(Java 反射篇)
    Step By Step(Java 国际化篇)
  • 原文地址:https://www.cnblogs.com/stono/p/4974623.html
Copyright © 2011-2022 走看看