问题描述
我的RequestInfo.java内容为importjava.io.*;importjavax.servlet.*;importjavax.servlet.http.*;publicclassRequestInfoextendsHttpServlet{publicvoiddoGet(HttpServletRequestrequest,HttpServletResponseresponse)throwsIOException,ServletException{response.setContentType("text/html");//先设置Header,在这里只设置ContentType一项PrintWriterout=response.getWriter();//得到文本输出Writer//下面打印相关的HTMLout.println("<html>");out.println("<head>");out.println("<title>RequestInformationExample</title>");out.println("</head>");out.println("<body>");out.println("<h3>RequestInformationExample</h3>");out.println("RequestURI:"+request.getRequestURI()+"<br>");//打印请求的路径out.println("Protocol:"+request.getProtocol()+"<br>");//打印协议名称out.println("PathInfo:"+request.getPathInfo()+"<br>");//打印额外的路径信息out.println("RemoteAddress:"+request.getRemoteAddr());//打印客户机的地址,如果没有打印IP地址out.println("</body>");out.println("</html>");out.close();//关闭Writer}publicvoiddoPost(HttpServletRequestrequest,HttpServletResponseresponse)throwsIOException,ServletException{//如果是POST请求类型,同样调用GET类型的响应函数doGet(request,response);}}web.xml中servlet的配置为<servlet><servlet-name>RequestInfo</servlet-name><servlet-class>RequestInfo</servlet-class></servlet><servlet-mapping><servlet-name>RequestInfo</servlet-name><url-pattern>/RequestInfo</url-pattern></servlet-mapping>RequstInfo.class也放在了webapps/myapp/WEB-INF/classes目录内了
解决方案
解决方案二:
<servlet-class>RequestInfo</servlet-class>package要加上