Parameters between JSP and Controller

Controller

private void processRequest(HttpServletRequest request, HttpServletResponse response) 
        throws ServletException, IOException {
    
    //set
    //request
    ArrayList mlist = mg.searchAllMovies();
    request.setAttribute("mlist", mlist);
    
    //session
    Person p = new Person();
    p.setId(request.getParameter("username"));
    p.setPw(request.getParameter("password"));
    
    HttpSession session = request.getSession();
    session.setAttribute("person", p);
    session.setAttribute("person", null);
    
    //application
    ServletContext application = request.getServletContext();
    application.setAttribute("key3", "global variable");
    
    
    //get
    //request
    String readfromrequest = (String) request.getAttribute("key1");
    String projectRootPath = request.contextPath();
    String currentShortPath = request.getPathInfo();
    switch (path) {
            case "/list":

    //session
    HttpSession session = request.getSession();
    Person p = (Person) session.getAttribute("person");
    
    //application
    String readfromapplication = (String) request.getServletContext().getAttribute("key3");
    
    //get from JSP (Form or URL)
    string u = request.getParameter("username");    
    
}

JSP

<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>


Home














    
  • MyPage
  • Add

    你可能感兴趣的:(Parameters between JSP and Controller)