HttpServletRequest의 메서드들
🟣 결과
- HttpServletRequestMethod.java
@Controller
@RequestMapping("request")
public class HttpServletRequestMethod {
@RequestMapping("sample1")
public String main(HttpServletRequest request, Model model) {
String scheme = request.getScheme();
String method = request.getMethod();
String serverName = request.getServerName();
int serverPort = request.getServerPort();
String contextPath = request.getContextPath();
String servletPath = request.getServletPath();
String requestURI = request.getRequestURI();
String requestURL = request.getRequestURL().toString();
String queryString = request.getQueryString();
model.addAttribute("scheme",scheme);
model.addAttribute("method",method);
model.addAttribute("serverName",serverName);
model.addAttribute("serverPort",serverPort);
model.addAttribute("contextPath",contextPath);
model.addAttribute("servletPath",servletPath);
model.addAttribute("requestURI",requestURI);
model.addAttribute("requestURL",requestURL);
model.addAttribute("queryString",queryString);
return "method";
}
}
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>HttpServletRequest test file</title>
</head>
<body>
<h1>HttpServletRequest의 method들 정리</h1>
<h2>http://localhost:8080/ch2/request/sample1?value</h2>
<h2>getScheme()</h2>
<h3><span>scheme : ${scheme}</span></h3>
<h2>getMethod()</h2>
<h3><span>method : ${method}</span></h3>
<h2>getServerName()</h2>
<h3><span>serverName : ${serverName}</span></h3>
<h2>getServerPort()</h2>
<h3><span>serverPort : ${serverPort}</span></h3>
<h2>getContextPath()</h2>
<h3><span>contextPath : ${contextPath}</span></h3>
<h2>getServletPath()</h2>
<h3><span>servletPath : ${servletPath}</span></h3>
<h2>getServletURI()</h2>
<h3><span>requestURI : ${requestURI}</span></h3>
<h2>getServletURL()</h2>
<h3><span>requestURL : ${requestURL}</span></h3>
<h2>getQueryString()</h2>
<h3><span>queryString : ${queryString}</span></h3>
</body>
</html>
HttpServletRequest의 method들 정리
http://localhost:8080/test/request/sample1?value
getScheme()
scheme : http
getMethod()
method : GET
getServerName()
serverName : localhost
getServerPort()
serverPort : 8080
getContextPath()
contextPath : /test
getServletPath()
servletPath : /request/sample1
getServletURI()
requestURI : /test/request/sample1
getServletURL()
requestURL : http://localhost:8080/test/request/sample1
getQueryString()
queryString : value