본문 바로가기

C.E/Java[atc.]

Hello?

간단히 Hello?를 출력하는 브라우저를 만들어봅시다.

 

 

 

1)

이클립스로 소스를 입력합니다.



 


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 Hello extends HttpServlet{ @Override protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { PrintWriter writer=resp.getWriter(); writer.println("Hello?"); } }


 


2)

\Tomcat 7.0\webapps\JPcourse\WEB-INF\classes 폴더에 Hello.class를 저장합니다.

- Hello.class는 ..\bin 안에 있습니다.

 

 

 

3)

\Tomcat 7.0\webapps\JPcourse\WEB-INF\web.xml 을 다음과 같이 수정합니다.

 


<?xml version="1.0" encoding="ISO-8859-1"?>
<!--
 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.
-->

 

<?XML:NAMESPACE PREFIX = "[default] http://java.sun.com/xml/ns/javaee" NS = "http://java.sun.com/xml/ns/javaee" /><web-app xmlns="http://java.sun.com/xml/ns/javaee" metadata-complete="true" version="3.0" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee&#13;&#10;                      http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">

  <servlet>
 <servlet-name>Hello</servlet-name>
 <servlet-class>Hello</servlet-class>
  </servlet>
  <servlet-mapping>
 <servlet-name>Hello</servlet-name>
 <url-pattern>/Hello</url-pattern>
  </servlet-mapping>



4)

크롬을 실행하여 주소표시줄에 http://localhost:8080/Hello 를 입력하여 실행합니다.

 

 

 

5)

브라우저에 Hello?가 뜬다면 정상입니다.

 

 

* xml이 몇몇 부분이 웹이라 정상적으로 보이지 않아서 첨부해두었습니다.

 

web.xml

 

 

 

 

 

 

'C.E > Java[atc.]' 카테고리의 다른 글

안드로이드 스튜디오 SDK 깔기.  (0) 2015.10.07
apache tomcat 7.0을 이용한 자바프로그래밍  (0) 2013.12.02