我想在我的jetty v9.1中部署一個簡單的Helloworld webapp。我有當我試圖訪問servlet的問題,我recive的錯誤消息:不能做一個簡單的HelloWorld碼頭webapp
HTTP ERROR 404
問題存取/ HelloServlet /的servlet。原因:
Not Found
我知道我在這裏做錯了什麼,但我不知道是什麼。
這裏是Webbapp在碼頭我的文件結構:
的webapps
+例如
+你好
的hello.xml 的index.html + WEB-INF
的web.xml +類
HelloServlet.class
的index.html + WEB-INF(代表一個文件夾,WEB-INF和a index.html文件,在同一個文件夾你好)
這裏是我的web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app
xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
version="2.5">
<display-name>Example</display-name>
<!-- Declaraa existenta unui servlet. -->
<servlet>
<servlet-name>HelloServlet</servlet-name>
<servlet-class>HelloServlet</servlet-class>
</servlet>
<!-- Map URLs to that servlet. -->
<servlet-mapping>
<servlet-name>servlet</servlet-name>
<url-pattern>/servlet</url-pattern>
</servlet-mapping>
HelloServlet.java
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;
public class HelloServlet extends HttpServlet {
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException {
String input=request.getParameter("input");
PrintWriter out=response.getWriter();
out.println("<html>");
out.println("<body>");
out.println("The parameter input was \" "+input+"\" .");
out.println("</body");
out.println("</html");
}
protected void doPost(HttpServletRequest request,HttpServletResponse response) throws IOException {
String field=request.getParameter("field");
PrintWriter out=response.getWriter();
out.println("<html>");
out.println("<body>");
out.println("You entered \" "+field+"\" into the text box.");
out.println("</body>");
out.println("</html>");
}
}
的index.html
<html>
<head>
<title>Example Web Application</title>
</head>
<body>
<p>This is a static document with a form in it.</p>
<form method="POST" action="servlet">
<input name="field" type="text" />
<input type="submit" value="Submit" />
</form>
</body>
</html>
打招呼。XML
<<?xml version="1.0" encoding="ISO-8859-1"?>
<<!DOCTYPE Configure PUBLIC "-//Jetty//Configure//EN" "http://www.eclipse.org/jetty/configure_9_0.dtd">
<<Configure class="org.eclipse.jetty.webapp.WebAppContext">
<Set name="contextPath">/hello</Set>
<Set name="extractWAR">false</Set>
<Set name="copyWebDir">false</Set>
<Set name="defaultsDescriptor"><Property name="jetty.home" default="."/>/etc/webdefault.xml</Set>
<Call name="setAttribute">
<Arg>org.eclipse.jetty.websocket.jsr356</Arg>
<Arg type="Boolean">true</Arg>
</Call>
<Get name="securityHandler">
<Set name="loginService">
<New class="org.eclipse.jetty.security.HashLoginService">
<Set name="name">Test Realm</Set>
<Set name="config"><SystemProperty name="jetty.base" default="."/>/etc/realm.properties</Set>
</New>
</Set>
<Set name="authenticator">
<New class="org.eclipse.jetty.security.authentication.FormAuthenticator">
<Set name="alwaysSaveUri">true</Set>
</New>
</Set>
<Set name="checkWelcomeFiles">true</Set>
</Get>
</Configure>
是的,你是正確的probaly關於Spring,但我必須使用這種風格的時刻,所以我可以瞭解servlet和碼頭,我在這個新的,所以索里約的愚蠢的問題。我也想你的建議,但我仍然得到同樣的錯誤,我甚至試着讓url-pattern的AS/servlet和使用前綴的servlet –
@AdrianTotolici就像我說的,這是很好的知道的事情在較低水平是如何工作的。我不確定你說的你做了什麼不同。請發佈您嘗試加載的整個網址。 – chrylis
的http://本地主機:8080/servlet中,我也編在URL中的新的修改我的問題上面 –