Java Servlet ??????????
???????????? ???????[ 2015/11/3 17:15:37 ] ??????????????? ???????????
????????
????????????stackoverflow???????????Java Servlet????????????ν???????????????????????????
????????Servlet????ι??????Servlet ????????????????????????ж????????
???????????????????????? Servlet ?? web ??????????? Servlet ??????????? Servlet ????????????? session ??????
????????????????????????????????????????????????? session ???????????仯????????????????????ù?????????????????????????????????????????????????????????????????
??????????????????????? *n* ????????????????? Servlet??????? Servlet ??????????????η??????????????????????????????????
???????BalusC????
????ServletContext
?????? Servlet ?????????? Apache Tomcat??????????????????? web ??á???web ?????????Servlet ??????????? ServletContext??????????????????????С?web ???? web.xml ??????????????????? servlet??filter ?? Listener ?? @WebServlet??@WebFilter ?? @WebListener ???????????????β????浽????????????С????????й??????????????? init()???? Servlet ??????????ж?????? web ???????????г?????? Servlet ????????? destroy() ??????????? ServletContext ?????? Servlet??Filter ?? Listener ?????
???????????е? Servlet ????? load-on-startup ???? @WebServlet(loadOnStartup) ????????????? 0 ?????????????????????????????? init() ??????“load-on-startup”?е???????Щ Servlet ??????????????????????????????????? web.xml ??????????? @WebServlet ?????????????????????? “load-on-startup” ???init() ??????????? HTTP ?????????????е? Servlet ???????á?
????HttpServletRequest ?? HttpServletResponse
????Servlet ????????????? web ?????????? web ??????????????????? HTTP ????????????????????????? 8080???????????????? 80??????????web ???????????????? HTTP ????Servlet ?????????μ? HttpServletRequest ?? HttpServletResponse ???????????????ò???????? URL ??? url-pattern ?? Filter ?? Servlet ????е?????????й???????????????д????
????request ?????????????и? HTTP ?????е?????????? request header ?? request body??response ????????????????????? HTTP ????????????????? header ?? body?????????? JSP ????е? HTML ??????????????HTTP ??????????? request ?? response ????
????HttpSession
?????????????η???? web ??????????? request.getSession() ????λ?? HttpSession????? Servlet ?????????? HttpSession??????????? ID????????? session.getId() ??????????????????????С???? Servlet ???????? HTTP ????? Set-Cookie ?????????? Cookie???? JSESSIONID ??? Cookie ?????????? session ID ??? Cookie ?????
???????? HTTP cookie ???????? web ??????? web ????????????????????? cookie ??Ч???????????????????????????? Cookie ??з?????? cookie??????????????? HTTP ???????????????????????? Chrome??Firefox23+??IE9+ ?а? F12?????? Net/Network ???????Servlet ??????????????????? HTTP ????? Cookie ????????????JSESSIONID ?? cookie??????????????session ID?????????????????????? HttpSession??
??????????? web.xml ?????? session-timeout ??????? 30 ?????????????? HttpSession ??????????????????????? web ??ó??? 30 ?????Servlet ???????????? session??????????????????? cookie ???????????????????? session??Servlet ????????????μ? Cookie??
??????????棬???????? session cookie ???????????????????????????????????????????????????????????????????????б????????????? session ??????????????????????????????? session ?????? cookie??????μ? request.getSession() ???????μ? HttpSession ?????????????? session ID ?? cookie??
????????
????ServletContext ?? web ??????????????????????? session ?е????????????
????????????????????????????web??y?????????г????HttpSession??????
????HttpServletRequest ?? HttpServletResponse ???????????????????????????????web ??棩???????????????????????????
???????? Servlet??Filter ?? Listener ?????? web ?????????????????????????? session ?е????????
???????????? HttpServletRequest??HttpServletResponse ?? HttpSession ?е????????????????е??????????????????
?????????
??????????????????????????????????????????? Servlet ?? filter ????????????????? Java ??????????????????????? HTTP ???????????????????????????????????′???????????????????
??????????????????????????κ? request ?? session ???е????????? servlet ?? filter ????????????????????????? session ?е????????????????????????????????????????????????????
????public class ExampleServlet extends HttpServlet {
????private Object thisIsNOTThreadSafe;
????protected void doGet(HttpServletRequest request?? HttpServletResponse response) throws ServletException?? IOException {
????Object thisIsThreadSafe;
????thisIsNOTThreadSafe = request.getParameter("foo"); // BAD!! Shared among all requests!
????thisIsThreadSafe = request.getParameter("foo"); // OK?? this is thread safe.
????}
????}
??????
???·???
??????????????????
2023/3/23 14:23:39???д?ò??????????
2023/3/22 16:17:39????????????????????Щ??
2022/6/14 16:14:27??????????????????????????
2021/10/18 15:37:44???????????????
2021/9/17 15:19:29???·???????·
2021/9/14 15:42:25?????????????
2021/5/28 17:25:47??????APP??????????
2021/5/8 17:01:11