麻豆小视频在线观看_中文黄色一级片_久久久成人精品_成片免费观看视频大全_午夜精品久久久久久久99热浪潮_成人一区二区三区四区

首頁 > 學院 > 開發設計 > 正文

servlet

2019-11-11 05:08:58
字體:
來源:轉載
供稿:網友

常用的web服務器有: 1、IIS,出自微軟 2、Apache,linux,C語言寫的 3、tomcat是Apache項目中的一個,java寫的

servlet是服務器上運行的程序其主要功能在于交互式地瀏覽和修改數據,生成動態Web內容。

先記錄下功能代碼吧,關于servlet的原理,等之后學習更深入了,再補充一下。

生命周期public class TestLiftCycleServlet extends HttpServlet { /** * 實例化 */ public TestLiftCycleServlet() { System.out.session-Cookie-"+i,"Cookie-Value_S"+i); resp.addCookie(cookie); cookie= new Cookie("Persistent-Cookie-"+i, " hello"); cookie.setMaxAge(3600);//時效性 resp.addCookie(cookie); } //設置網頁的字符編碼格式為gb2312 resp.setContentType("text/html;charset=gb2312"); PrintWriter pw = resp.getWriter(); //2 獲取cookie pw.println("獲取到cookie"); Cookie[] cookies = req.getCookies(); if(cookies!=null){ Cookie cookie = null; for(int i = 0; i < cookies.length; i++){ cookie= cookies[i]; pw.println("name:"+cookie.getName()+" value:"+cookie.getValue()); } } } @Override protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { System.out.println("post"); doGet(req, resp); }}關于Session/** * * session是存在服務器端的,cookie是存在客戶端的。 * session可與瀏覽器關聯,每個窗口有獨一無二的sessionId.session就是服務端的一個內存,能存儲任何內容。鍵值對 * session是針對窗口的。不像cookie擁有路徑訪問問題,同一個application下的servlet/jsp可以共享一個session。需要同一個客戶端窗口 * * 如果瀏覽器支持cookie,創建session時會把sessionId保存在cookie里,保持不變。否則sessionId每次都說新生成的 * * session實現: cookie實現、url重寫實現 * * * cookie(臨時的,寫在文件里)實現:sessionId存在臨時cookie里 * 使用url重寫的方式實現session,response。encodeURL(),轉碼,url后面添加sessionId * *http://blog.csdn.net/robbyo/article/details/17733743 */public class SessionDemo extends HttpServlet { @Override protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { //獲取當前的session,若無,就創建一個session HttpSession mySession = req.getSession(true); resp.setContentType("text/html"); PrintWriter out= resp.getWriter(); String heading; Integer accessCount = (Integer)mySession.getAttribute("accessCount"); if(accessCount==null){ accessCount = new Integer(0); heading="welcome,new comer"; }else{ heading="welcome back"; accessCount = new Integer(accessCount.intValue()+1); } mySession.setAttribute("accessCount", accessCount); out.println("<H3>show info saved in session</H3>"+accessCount); out.println("<H3>create Information</H3>"); out.println(" new Session:"+mySession.isNew()); out.println("session id:"+mySession.getId()+ ",create time:"+mySession.getCreationTime() //最近一次訪問的時間,session是有過期時間的 +",last access time:"+mySession.getLastAccessedTime()); out.println("<H3>Request Information</H3>"); out.println("Session ID from Request: " //上次使用的session + req.getRequestedSessionId()); out.println("<BR>Session ID via Cookie: " //方式1:通過cookie + req.isRequestedSessionIdFromCookie()); out.println("<BR>Session ID via rewritten URL: " //方式2:通過重寫url + req.isRequestedSessionIdFromURL()); out.println("<BR>Valid Session ID: " //session是否有效 + req.isRequestedSessionIdValid()); //添加了一個刷新,瀏覽器不使用cookie,就在url里面添加session out.println("<a href="+"SessionDemo"+">simple url </a>"); //經測試,360不行,Chrome可以.response.encodeURL的功能是url后添加session。 String urlWithSession = resp.encodeURL("SessionDemo"); out.println("<a href='"+urlWithSession+"'>url with session</a>"); out.close(); // close output stream } @Override protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { System.out.println("post"); doGet(req, resp); }}application/** * application里面的值是共享的 * @author dell * */public class TestServletContext extends HttpServlet { @Override protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { resp.setContentType("text/html;charset=gb2312"); PrintWriter out = resp.getWriter(); //獲取application ServletContext application = this.getServletContext(); //設置application里的內容 Integer accessCount = (Integer)application.getAttribute("accessCount"); if(accessCount==null){ accessCount = new Integer(0); }else{ accessCount = new Integer(accessCount.intValue()+1); } application.setAttribute("accessCount", accessCount); //獲取application里的內容 out.println("get count:"+accessCount); }}
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 久久亚洲国产精品 | 高清中文字幕在线 | 亚洲国产成人久久一区www妖精 | 欧美成人精品欧美一级乱黄 | 成人毛片100部免费观看 | 久久亚洲春色中文字幕久久 | 欧美一级黄色片免费观看 | 成人在线视频在线观看 | 一级做a爱片毛片免费 | 操网 | 日韩中文字幕一区二区三区 | 成人一级视频 | 亚洲欧美在线视频免费 | 一级黄色毛片播放 | 久久精品视频在线 | 在线看小早川怜子av | 国产88久久久国产精品免费二区 | av电影手机在线看 | 久久欧美亚洲另类专区91大神 | 国产精品久久久久久久久久久久久久久久 | 91精品国产91久久久久久不卞 | 黄色一级片在线观看 | 少妇激情视频 | 欧美成人午夜一区二区三区 | 欧美成人精品一区二区 | 久久蜜桃香蕉精品一区二区三区 | 精品久久久久久久久久久久 | 羞羞视频免费网站入口 | 欧美国产日韩在线观看成人 | 国产porn在线 | 久久久久国产成人精品亚洲午夜 | 天天撸日日夜夜 | 在线观看av国产一区二区 | 99影视电影电视剧在线播放 | 久久我不卡 | 91精品国产综合久久久欧美 | 大西瓜永久免费av在线 | 综合网天天色 | 免费看成人av | 国产自在自线午夜精品视频在 | 亚洲精久 |