我想在我的 maven 项目中编写一个简单的 servlet,但我收到此错误,在此服务器上找不到请求的 url (/src/main/java/web.servlets.FunctionalTestServlet)。
这是我的代码:
Servlet:位于 src/main/java 包 web.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 FunctionalTestServlet extends HttpServlet
{
public void doGet(HttpServletRequest request,HttpServletResponse response)throws
ServletException, IOException {
PrintWriter out = response.getWriter();
out.println( "SimpleServlet Executed" );
out.flush();
out.close();
}
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws IOException, ServletException{
response.setContentType("text/html");
PrintWriter out = response.getWriter();
String fileName = request.getParameter("testfile");
out.println("<b><font color='blue'>The File name is
:</font></b>"
+ "<b>"+ fileName +"</b>" + "<br>");
}
}
jsp页面:在src/main/webapp下
<html:file properties="tonFichier" name="tonForm"/>
<form action="/src/main/java/web.servlets.FunctionalTestServlet"
enctype="multipart/form-data" method="post">
<p>
Type some text (if you like):<br>
<input type="text" name="textline" size="30">
</p>
<p>
Please specify a Test , or a set of tests:<br>
<input type="file" name="testfile" size="40" >
</p>
<div>
<input type="submit" value="Execute Test">
</div>
</form>
</body>
</html>
这是我的 web.xml:在 /WebTestAutomatisation/src/main/webapp/WEB-INF/web.xml
<!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
"http://java.sun.com/dtd/web-app_2_3.dtd" >
<web-app>
<display-name>Archetype Created Web Application</display-name>
<servlet>
<servlet-name>FunctionalTestServlet</servlet-name>
<servlet-class>web.servlets.FunctionalTestServlet.java</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>FunctionalTestServlet</servlet-name>
<url-pattern>/*</url-pattern>
</servlet-mapping>
</web-app>