我正在编写一些基本的servlet,并且我在链接http://localhost:8080/Parameters/wypisz_parametry?parametr1=java¶metr2=start¶metr3=javaEE中传递参数,但是当我输入它时,我得到404错误。
的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" id="WebApp_ID" version="3.0">
<servlet>
<servlet-name>Parameters</servlet-name>
<servlet-class>pl.javastart.servlets.wypisz_parametry.java</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>Parameters</servlet-name>
<url-pattern>/wypisz_parametry</url-pattern>
</servlet-mapping>
</web-app>
wypisz_parametry类:
package pl.javastart.servlets;
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 wypisz_parametry extends HttpServlet {
private static final long serialVersionUID = 1321321321L;
public void doGet(HttpServletRequest request,
HttpServletResponse response) throws ServletException, IOException {
PrintWriter out = response.getWriter();
String parametr1 = request.getParameter("parametr1");
String parametr2 = request.getParameter("parametr2");
String parametr3 = request.getParameter("parametr3");
out.println("Wczytanie 3 parametrow z zadania :");
out.println(parametr1);
out.println(parametr2);
out.println(parametr3);
}
}
答案 0 :(得分:0)
错误在web.xml中,类名应该没有.java
<servlet-class>pl.javastart.servlets.wypisz_parametry</servlet-class>