您好,登錄后才能下訂單哦!
請求行:
package?com.my.servlet; ? import?java.io.IOException; import?java.io.InputStream; import?java.io.PrintWriter; import?java.net.URL; ? import?javax.servlet.ServletConfig; import?javax.servlet.ServletContext; import?javax.servlet.ServletException; import?javax.servlet.annotation.WebServlet; import?javax.servlet.http.HttpServlet; import?javax.servlet.http.HttpServletRequest; import?javax.servlet.http.HttpServletResponse; ? /** ?*?Servlet?implementation?class?ContextServlet ?*/ @WebServlet("/ContextServlet") public?class?ContextServlet?extends?HttpServlet?{ private?static?final?long?serialVersionUID?=?1L; ??????? ????/** ?????*?@see?HttpServlet#HttpServlet() ?????*/ ????public?ContextServlet()?{ ????????super(); ????} ???? /** ?*?@see?HttpServlet#doGet(HttpServletRequest?request,?HttpServletResponse?response) ?*/ protected?void?doGet(HttpServletRequest?request,?HttpServletResponse?response)?throws?ServletException,?IOException?{ response.setContentType("text/html;charset=UTF-8"); String?method?=?request.getMethod();//獲取使用的HTTP方法; String?URi?=?request.getRequestURI();//獲取請求中的資源名部分 String?protocol?=?request.getProtocol();//獲得協議號 String?queryString?=?request.getQueryString();//獲得查詢語句 String?servletPath?=?request.getServletPath(); String?contextpath?=?request.getContextPath();//獲得web應用路徑 PrintWriter?out?=?response.getWriter(); out.println("<p>請求使用的http方法"+method+"</p>"); out.println("<p>請求行中的資源名部分"+URi+"</p>"); out.println("<p>請求使用的協議"+protocol+"</p>"); out.println("<p>查詢字符串"+queryString+"</p>"); ? out.println("<p>Servlet所映射的路徑"+servletPath+"</p>"); out.println("<p>請求資源所屬的WEb應用路徑"+contextpath+"</p>"); out.flush(); ? out.close(); } ? protected?void?doPost(HttpServletRequest?request,?HttpServletResponse?response)?throws?ServletException,?IOException?{ ? doGet(request,?response); ? } ? }
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。