0

我正在学习 servlet。出于某种原因,我收到 404 错误,我无法指出原因。

一些信息: 1. 该项目启用了动态 Web 模块。2.项目已添加到服务器。

任何帮助将非常感激。代码 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">
  <display-name>SimpleServletProject</display-name>

    <servlet>
      <servlet-name>xmlServlet</servlet-name>
      <servlet-class>org.calgar.javastuff.XmlServlet</servlet-class>
    </servlet>
    <servlet-mapping>
         <servlet-name>xmlServlet</servlet-name>
         <url-pattern>/xmlServletPath</url-pattern>
    </servlet-mapping>
</web-app>

xmlservlet.java

public class XmlServlet extends HttpServlet {

   protected void doGet(HttpServletRequest request, HttpServletResponse response)    throws ServletException, IOException {
    System.out.println("xml servlet called");
    response.setContentType("text/html");

PrintWriter writer = response.getWriter();
String userName = request.getParameter("userName");

HttpSession session = request.getSession();
ServletContext context = request.getServletContext();
if(userName != "" && userName !=null )
{
    session.setAttribute("savedUserName", userName);
    context.setAttribute("savedUserName", userName);
}
writer.println("Request parameter username: " + userName);
writer.println("Session parameter username: " + (String) session.getAttribute("savedUserName"));
writer.println("Context parameter username: " + (String) context.getAttribute("savedUserName"));

;

}

4

0 回答 0