We will manipulate some form values in jsp. Or obtain the user's value operation, then we can use the scope operation of jsp, 1.page, request, session, and application, among which the most commonly used are the domain operations of request and session.
Use the session domain operation, because the web container used is the Tomcat server, and as long as the session does not close the browser, it will exist and will not disappear. It is still the default time limit of 30 minutes. Then the next step is to use the session in jsp.
<%@ page language="java" contentType="text/html; charset=UTF-8"pageEncoding="UTF-8"%><!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"><html><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"><title>Insert title here</title></head><body><form method=POST action="Session.jsp">
Please enter your username:
<input type=text name="name"> <input type=submitvalue="submit information"></form><!-- session setting value--><%String name = request.getParameter("name");session.setAttribute("name", name);String names = (String) session.getAttribute("name");%>Your username is: <%=names%></body></html>
At this time, you will get the value of this name and you can operate this session and reply.
JSTL tag gets Session:
session.setAttribute("age","123");
${ sessionScope.age} shows 123 on the page
sessionScope refers to the scope of session, similar to requestScope, pageScope, contextScope, etc.
Then the following age represents the key value when the set attribute
Get Session in Jsp:
session is a built-in object for jsp, so you can write it directly in jsp
<% session.setAttribute("a", b); //Put b into session and name it a, String M = session.getAttribute("a").toString(); //Pick out a from session and assign it to M %>Summarize
The above is all the brief introduction to the access to session values in JSP, I hope it will be helpful to everyone. Interested friends can continue to refer to this site:
Detailed explanation of the implementation of intercepting function for unlogged jsp pages in Struts2
jsp-Solve the problem of automatic file deletion when restarting Tomcat after file upload
If there are any shortcomings, please leave a message to point it out. Thank you friends for your support for this site!