以下是我写的一个小程序:但访问路径总是出错:
ipaddress类中:(在文件夹E:jspipaddressWEB-INFclassesinbinjsp1)
package binbin.jsp1;
import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
public class Ipaddress extends HttpServlet {
public void init(ServletConfig config)
throws ServletException {
super.init(config);
}
public void doGet(HttpServletRequest request,HttpServletResponse response)
throws ServletException,IOException{
doPost(request,response);
}
public void doPost(HttpServletRequest request,HttpServletResponse response)
throws ServletException,IOException{ 数据挖掘研究院
response.setContentType("text/html");
PrintWriter out=response.getWriter();
out.println(" <html> ");
out.println(" <head> <title> Simple Servlet </title> </head> ");
out.println(" <body> ");
out.println(" <center> <font size=6 color=red> ");
out.println("Your address is "+ request.getRemoteAddr()+"
");
out.println(" </font> </certer> ");
out.println(" </body> </html> ");
out.close();
}
}
web.xml中:(在文件夹E:jspipaddressWEB-INF)
<?xml version="1.0" encoding="utf-8"?>
<web-app>
<servlet>
<servlet-name> Ipaddress </servlet-name>
<servlet-class> binbin.jsp1.Ipaddress </servlet-class>
</servlet>
<servlet-mapping>
<servlet-name> Ipaddress </servlet-name>
<url-pattern> /GetAddress </url-pattern>
</servlet-mapping>
</web-app>
我在IE中使用 http://127.0.0.1/ipaddress/GetAddress 显示错误:
HTTP Status 404 - /ipaddress/GetAddress
--------------------------------------------------------------------------------
type Status report
message /ipaddress/GetAddress 数据挖掘实验室
description The requested resource (/ipaddress/GetAddress) is not available.
--------------------------------------------------------------------------------
Apache Tomcat/5.5.25
本人初学,请勿见笑。折腾到半夜,终于搞定了,原来是Tomcat 5.5confCatalinalocalhost文件夹底下少创建了一个包含context标签的ipaddress.xml文件。Create By Any-Extract(WL-AE)
数据挖掘论坛