溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊(cè)×
其他方式登錄
點(diǎn)擊 登錄注冊(cè) 即表示同意《億速云用戶服務(wù)條款》

javaWeb HttpServletRequest接口

發(fā)布時(shí)間:2020-07-24 14:30:38 來(lái)源:網(wǎng)絡(luò) 閱讀:191 作者:louyixiao 欄目:開(kāi)發(fā)技術(shù)

請(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);
?
	}
?
}


向AI問(wèn)一下細(xì)節(jié)

免責(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)容。

AI