Controller
private void processRequest(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
//set
//request
ArrayList<Movie> 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"%>
<!-- request -->
<!-- get pageContext root path -->
<td><a href="${pageContext.request.contextPath }/HomePage.jsp">Home</a></td>
<!-- get para form request -->
<!--following is ok -->
<c:forEach var="hero" items="${mlist}">
<c:forEach var="hero" items="${param.mlist}">
<c:forEach var="hero" items="${param["mlist"]}">
<c:forEach var="hero" items="${param['mlist']}">
<c:forEach var="hero" items="${requestScope.mlist}">
<c:forEach var="hero" items="${requestScope["mlist"]}">
<c:forEach var="hero" items="${requestScope['mlist']}">
<!-- session -->
<c:if test="${sessionScope.role.equals('Admins')}">
<li><a href="${pageContext.request.contextPath }/loadData">MyPage</a></li>
</c:if>
<c:url var="addurl" scope="page" value="/views/Admin/SetUpPageCourse.jsp">
<c:param name="newCourseID" value="${sessionScope.newCourseID }" />
<c:param name="insert" value="true" />
</c:url>
<a href="${addurl}">Add</a>