405 오류 - 허용되지 않는 메소드
코드
import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
@WebServlet("/user")
public class UserServlet extends HttpServlet{
@Override
protected void service(HttpServletRequest arg0, HttpServletResponse arg1)
throws ServletException, IOException {
//getMethod() : method방식을 파싱해서 가져옴
if(arg0.getMethod().equals("GET")) {
System.out.println("GET 요청입니다.");
} else if(arg0.getMethod().equals("POST")) {
System.out.println("POST 요청입니다.");
}
//부모클래스의 service메서드를 호출해주면 반드시 do post, do get메서드 추가
super.service(arg0, arg1);
}
→ 콘솔창에는 method 방식이 뜨나 브라우저에는 405 오류가 뜬다.
→ super.service(arg0, arg1) 넣었을 경우 doPost, doGet메서드 처리를 해주지 않았기 때문
해결방법
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException {
}
@Override
protected void doPost(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException {
}
→ doGet, doPost 메서드 추가
404 오류 - 찾을 수 없음
이유
param_p.jsp 파일이 위치한 webapp 폴더에 놔야하는데
나는 attribute 폴더에 넣어서 계속 찾을 수 없다고 뜬 것이었다.
해결방법
→ 파일 위치 확인