The requested resource is not available

sunny冰青 发布于 2015/02/01 00:45
阅读 1K+
收藏 0
package com.demo;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * Servlet implementation class FirstServlet
 */
@WebServlet("/123")
public class FirstServlet extends HttpServlet {
    private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public FirstServlet() {
        super();
        // TODO Auto-generated constructor stub
    }

    /**
     * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
     */
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        // TODO Auto-generated method stub
        response.setContentType("text/html; charset=utf-8");
        PrintWriter out = response.getWriter();
        out.println("<html>");
        out.println("<head><title>Welcome to Servlet!</title></head>");
        out.println("<body>");
        out.println("<h1>Hello World!</h1>");
        out.println("</body>");
        out.println("</html>");
        out.flush();
        out.close();
    }

}

<?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"
    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>FirstServlet</display-name>
  <servlet>
      <servlet-name>First</servlet-name>
      <servlet-class>com.demo.FirstServlet</servlet-class>
  </servlet>
  <servlet-mapping>
      <servlet-name>First</servlet-name>
      <url-pattern>/123</url-pattern>
  </servlet-mapping>
 
</web-app>

各种配置和路径都没有错,不知为何会报404错

加载中
0
lgscofield
lgscofield
注解先去掉实再访问或者取得url-pattern中的123直接/就行
lgscofield
lgscofield
@sunny冰青 有多种方法,可以在web.xml中添加欢迎页,可以过滤器实现等等。。。
s
sunny冰青
大神,我明白你说的意思了。可以怎么设置让它可以直接显示出来而不用再输入/123
s
sunny冰青
还是没用啊
返回顶部
顶部