您好,登錄后才能下訂單哦!
請(qǐng)求行:
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();//獲取請(qǐng)求中的資源名部分 String?protocol?=?request.getProtocol();//獲得協(xié)議號(hào) String?queryString?=?request.getQueryString();//獲得查詢語(yǔ)句 String?servletPath?=?request.getServletPath(); String?contextpath?=?request.getContextPath();//獲得web應(yīng)用路徑 PrintWriter?out?=?response.getWriter(); out.println("<p>請(qǐng)求使用的http方法"+method+"</p>"); out.println("<p>請(qǐng)求行中的資源名部分"+URi+"</p>"); out.println("<p>請(qǐng)求使用的協(xié)議"+protocol+"</p>"); out.println("<p>查詢字符串"+queryString+"</p>"); ? out.println("<p>Servlet所映射的路徑"+servletPath+"</p>"); out.println("<p>請(qǐng)求資源所屬的WEb應(yīng)用路徑"+contextpath+"</p>"); out.flush(); ? out.close(); } ? protected?void?doPost(HttpServletRequest?request,?HttpServletResponse?response)?throws?ServletException,?IOException?{ ? doGet(request,?response); ? } ? }
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。