scopedvars.java
来自「servletjsp一些应用程序」· Java 代码 · 共 36 行
JAVA
36 行
package coreservlets;
/** Servlet that creates some scoped variables (objects stored
* as attributes in one of the standard locations). Forwards
* to a JSP page that uses the expression language to
* display the values.
* <P>
* Taken from Core Servlets and JavaServer Pages 2nd Edition
* from Prentice Hall and Sun Microsystems Press,
* http://www.coreservlets.com/.
* © 2003 Marty Hall; may be freely used or adapted.
*/
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class ScopedVars extends HttpServlet {
public void doGet(HttpServletRequest request,
HttpServletResponse response)
throws ServletException, IOException {
request.setAttribute("attribute1", "First Value");
HttpSession session = request.getSession();
session.setAttribute("attribute2", "Second Value");
ServletContext application = getServletContext();
application.setAttribute("attribute3",
new java.util.Date());
request.setAttribute("repeated", "Request");
session.setAttribute("repeated", "Session");
application.setAttribute("repeated", "ServletContext");
RequestDispatcher dispatcher =
request.getRequestDispatcher("/el/scoped-vars.jsp");
dispatcher.forward(request, response);
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?