일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | |||
5 | 6 | 7 | 8 | 9 | 10 | 11 |
12 | 13 | 14 | 15 | 16 | 17 | 18 |
19 | 20 | 21 | 22 | 23 | 24 | 25 |
26 | 27 | 28 | 29 | 30 | 31 |
- Java
- exit code = -805306369
- graph database
- NestJS
- Maven Project
- tortoise SVN
- OGM
- springboot
- loadcomplete
- typeorm
- HTML Special Entity
- Spring Boot
- Next.js
- Spring
- tomcat
- Can't load AMD 64-bit .dll on a IA 32-bit platform
- JSP
- PostgreSQL
- maven
- HTML Code
- orioledb
- Eclipse
- 서브라임 텍스트
- Windows 10
- STS
- Spring Cloud
- BRIN
- MariaDB
- NextJs
- PG-Strom
- Today
- Total
Undergoing
web.xml 거치지 않고 Servlet 내에서 해결하기 본문
exerDispatcher.java
package ex01.ex01; import java.io.IOException; import java.util.ArrayList; import java.util.HashMap; 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 exerDispathcer */ public class exerDispatcher extends HttpServlet { private static final long serialVersionUID = 1L; HashMap map = new HashMap();
/** * @see HttpServlet#HttpServlet() */ public exerDispatcher() {
map.put("/EleServlet.im", new EleServlet()); // map.put("", new ()); } /** * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response) */ protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { doPostGet(request,response); } /** * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response) */ protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { doPostGet(request,response); }
protected void doPostGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException{
String path = request.getServletPath(); System.out.println(path);
defaultAction action = (defaultAction)map.get(path);
System.out.println(action+" <= is path mapping");
String result = action.execute(request,response); request.getRequestDispatcher(result).forward(request, response);
}
public void test() throws ClassNotFoundException, InstantiationException, IllegalAccessException{ Class clz = Class.forName("ex01.ex01.EightthServlet"); EightthServlet test= (EightthServlet)clz.newInstance(); test.myExecute();
} } |
DefaultAction.java
package ex01.ex01; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; public interface defaultAction { public String execute(HttpServletRequest request, HttpServletResponse response); } |
EleServlet.java
package ex01.ex01; import java.io.IOException; import javax.servlet.RequestDispatcher; 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 EightthServlet */ @WebServlet("/EleServlet") public class EleServlet implements defaultAction{ private String id = null;
public String execute(HttpServletRequest request, HttpServletResponse response){ String result = null; System.out.println("EleServlet loaded"); String id = request.getParameter("id");
result = "jsp/EleServletjsp.jsp";
return result; } } |
web.xml
<servlet> <description></description> <display-name>FirstServlet</display-name> <servlet-name>FirstServlet</servlet-name> <servlet-class>ex01.ex01.exerDispatcher</servlet-class> </servlet> <servlet-mapping> <servlet-name>FirstServlet</servlet-name> <url-pattern>*.im</url-pattern> </servlet-mapping>
</web-app> |
'개발 > Web Development' 카테고리의 다른 글
[Spring MVC/Tomcat] Tomcat 재기동시 페이지 접근 에러 발생 (0) | 2012.11.06 |
---|---|
[struts] xml에 있는 값 불러오기 (0) | 2012.08.31 |
커스텀 액션 - 태그 파일 (0) | 2012.06.05 |
JSTL (0) | 2012.06.01 |
Standard Action (0) | 2012.05.31 |