아이디어 구축 Servlet 실행 가능 한 웹 프로젝트

1. new Project
File > new > Project…

2.GroupID\\ArtifactID 작성
GroupID 는 프로젝트 조직의 유일한 식별 자 이 며,실제 JAVA 에 대응 하 는 가방 의 구 조 는 main 디 렉 터 리 에 있 는 자바 의 디 렉 터 리 구조 입 니 다.
ArtifactID 는 프로젝트 의 유일한 식별 자 입 니 다.실제 대응 하 는 프로젝트 의 이름 은 프로젝트 루트 디 렉 터 리 의 이름 입 니 다.

다음 길 Next 그리고 Finish 생 성 완료.
생 성 완료 후 다음 그림 과 같이:

3.자바 디 렉 터 리 만 들 기
 

main 디 렉 터 리 에서 오른쪽 클릭 하여 New Folder 를 선택 하 십시오.

자바 디 렉 터 리 를 Source 로 표시 합 니 다.

같은 리 소스 폴 더 를 다시 만 들 수 있 습 니 다.리 소스 형식 으로 표시 합 니 다.

완성 후:

4.Servlet 만 들 기
우선 Servlet 에 필요 한 의존 도 를 도입 합 니 다.

<dependency>
    <groupId>javax.servlet</groupId>
    <artifactId>servlet-api</artifactId>
    <version>2.5</version>
    </dependency>

MyServlet 를 작성 하여 HttpServlet 을 계승 하여 서비스 방법 을 실현 합 니 다.

public class MyServlet extends HttpServlet {

    @Override
    protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        //      
        request.setCharacterEncoding("utf8");
        //  request      username,password
        String username = request.getParameter("username");
        String password = request.getParameter("password");
        request.setAttribute("username",username);
        request.setAttribute("password",password);
        request.getRequestDispatcher( "/new.jsp").forward(request, response);;
    }
}
new.jsp

<html>
<body>
<h2>This is new Page</h2>
username: <%=request.getParameter("username") %>
<br>
password: <%=request.getParameter("password") %>
</body>
</html>
5.웹.xml 설정
웹.xml 를 설정 해 야 다른 사람 이 호출 할 수 있 습 니 다:

<!DOCTYPE web-app PUBLIC
"-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
"http://java.sun.com/dtd/web-app_2_3.dtd" >

<web-app>
<display-name>Archetype Created Web Application</display-name>

<servlet>
    <servlet-name>MyServlet</servlet-name>
    <servlet-class>club.sscai.demo.MyServlet</servlet-class>
</servlet>
<servlet-mapping>
    <servlet-name>MyServlet</servlet-name>
    <url-pattern>/MyServlet</url-pattern>
</servlet-mapping>

</web-app>
6.Tomcat 설정
직접 보기:
 
 

방문:http://localhost:8080/MyServlet?password=1111&username=222

servlet 에서 요청 응답 을 성공 적 으로 처리 하 였 습 니 다.이로써 maven 에서 프로젝트 를 만 드 는 데 성 공 했 습 니 다.
아이디어 가 Servlet 를 실행 할 수 있 는 웹 프로젝트 를 구축 하 는 것 에 관 한 이 글 은 여기까지 소개 되 었 습 니 다.더 많은 아이디어 가 Servlet 를 실행 하 는 내용 은 예전 의 글 을 검색 하거나 아래 의 관련 글 을 계속 조회 하 시기 바 랍 니 다.앞으로 저 희 를 많이 사랑 해 주세요!

좋은 웹페이지 즐겨찾기