Head First Java를 따르고 있습니다.Tomcat Eclipse에 간단한 서블릿 배포
지시 한대로 간단한 서블릿을 만들었지 만 배포 방법을 쓰지 않았습니다.
Tomcat 7에 배포하려고하는데 Eclipse를 통해 설정했습니다.
하지만 404 페이지 오류가 발생했습니다.
나는 web.xml을 만들었습니다. WEB-INF/classes에도 클래스 파일을 넣었습니다.
다음은 코드입니다.
package org.code;
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class KathyServlet extends HttpServlet {
public void doGet (HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
PrintWriter out;
String title = "PhraseOMatic has generated the following phrase.";
response.setContentType("text/html");
out = response.getWriter();
out.println("<HTML><HEAD><TITLE>");
out.println("PhraseOmatic");
out.println("</TITLE></HEAD><BODY>");
out.println("<H1>" + title + "</H1>");
out.println("<P>" + PhraseOMatic2.makePhrase());
out.println("<P><a href=\"KathyServlet\">make another phrase</a></p>");
out.println("</BODY></HTML>");
out.close();
}
}
다른 자바 코드 파일 :
package org.code;
public class PhraseOMatic2 {
public static String makePhrase() {
// make three sets of words to choose from
String[] wordListOne = {"24/7","multi-Tier","30,000 foot","B-to-B","win-win","front- end", "web-based","pervasive", "smart", "six-sigma","critical-path", "dynamic"};
String[] wordListTwo = {"empowered", "sticky", "valued-added", "oriented", "centric", "distributed", "clustered", "branded","outside-the-box", "positioned", "networked", "focused", "leveraged", "aligned", "targeted", "shared", "cooperative", "accelerated"};
String[] wordListThree = {"process", "tipping point", "solution", "architecture", "core competency", "strategy", "mindshare", "portal", "space", "vision", "paradigm", "mission"};
// find out how many words are in each list
int oneLength = wordListOne.length;
int twoLength = wordListTwo.length;
int threeLength = wordListThree.length;
// generate three random numbers, to pull random words from each list
int rand1 = (int) (Math.random() * oneLength);
int rand2 = (int) (Math.random() * twoLength);
int rand3 = (int) (Math.random() * threeLength);
// now build a phrase
String phrase = wordListOne[rand1] + " " + wordListTwo[rand2] + " " + wordListThree[rand3];
// now return it
return ("What we need is a " + phrase);
}
}
의 web.xml :
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" version="3.0">
<display-name>HFJse</display-name>
<servlet>
<servlet-name>kathyServlet</servlet-name>
<servlet-class>org.yasin.KathyServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>KathyServlet</servlet-name>
<url-pattern>/snoop/*</url-pattern>
</servlet-mapping>
</web-app>
죄송합니다. 잘못된 xml을 붙여 넣었습니다. xml을 올바른 패키지 이름으로 변경했지만 여전히 동일한 오류를 주었지만 소문자 kathy를 알지 못했지만 일단 변경된 후에는 정상적으로 작동했습니다. –