Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
Tags
- 자바 switch문
- 자바 public
- 이클립스 DB연동
- Til
- 자바 강제 캐스팅
- java
- 자바 조건문
- react ag grid
- 항해99
- 자바 삼항연산자
- TypeScript
- 자바 스캐너
- 자바 for문
- 자바
- 조코딩
- 자바 while문
- react with typescript
- 자바 공배수
- 자바 반복문
- Vue3
- 변수
- 자바 if문
- 자바 구구단 출력
- 자바 향상된 for문
- 정보처리기사실기
- 프로그래머스
- 자바 자동캐스팅
- 타입스크립트
- MySQL
- 항해99 2기
Archives
- Today
- Total
뇌 채우기 공간
[jsp] 이클립스에서 servlet 프로그램 만들고 실행해보기 본문
■ 브라우저에서 바로 열기
여기서 선택을 해주시면 자기가 선택한 웹 브라우저로 뜹니다.
■ 프로젝트 루트 설정하기
프로젝트 -> 우클릭-> 속성-> Web Project Settings에서 Context root를 /로 바꿉니다.
그리고 서버를 멈추어 줍니다.
아래에 있던 JSPprj를 delete합니다.
그리고 다시 실행합니다.
프로젝트로 안들어가고 바로 NewFile.jsp가 뜹니다.
■ 자바 코드 만들기
Java Resources에 src에 패키지와 클래스를 만들어줍니다.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
|
package com.newlecture.web;
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public class Nana extends HttpServlet{
@Override
protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
PrintWriter out = resp.getWriter();
out.println("Hello~~");
}
}
|
cs |
이렇게 적어주었습니다.
그리고 위의 경로에 있는 web.xml을 복사하여
WEB-INF안에 복사하여 넣습니다.
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
32
33
34
35
36
37
38
39
40
|
<?xml version="1.0" encoding="UTF-8"?>
<!--
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
this work for additional information regarding copyright ownership.
The ASF licenses this file to You under the Apache License, Version 2.0
(the "License"); you may not use this file except in compliance with
the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee
http://xmlns.jcp.org/xml/ns/javaee/web-app_4_0.xsd"
version="4.0"
metadata-complete="true">
<servlet>
<servlet-name>na</servlet-name>
<servlet-class>com.newlecture.web.Nana</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>na</servlet-name>
<url-pattern>/hello</url-pattern>
</servlet-mapping>
<display-name>Welcome to Tomcat</display-name>
<description>
Welcome to Tomcat
</description>
</web-app>
|
cs |
그리고 이렇게 수정을 해주었습니다.
servlet부분을 추가한 것입니다.
servlet-class태그안에는 패키지명.클래스명을 적어줍니다.
그러면 이렇게 실행이 됩니다.
728x90
'WEB > jsp' 카테고리의 다른 글
[jsp] annotation으로 url 매핑하기 (0) | 2020.12.28 |
---|---|
[jsp] 이클립스developer에서 jsp 실행하기 (0) | 2020.12.28 |
아파치 톰캣 설치하기 Apache Tomcat install/ 환경변수 설정하기 (0) | 2020.12.27 |