在IE上运行结果:
HTTP Status 404 - /ch02/SimpleServlet--------------------------------------------------------------------------------type Status reportmessage /ch02/SimpleServletdescription The requested resource (/ch02/SimpleServlet) is not available.
--------------------------------------------------------------------------------Apache Tomcat/6.0.26我用的软件是eclipse tomcat程序如下:
package test0;import java.io.IOException;
import java.io.PrintWriter;import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;@SuppressWarnings("serial")
public class SimpleServlet 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()"+"\n");
out.println("</center></font></body>");
out.println("</html>");
out.close();
}
}
class 的路径:D:\java\eclips\ch01\ch02\WEB-INF\classes\test0\SimpleServlet.classxml代码如下:
<?xml version="1.0" encoding="ISO-8859-1"?>
<web-app xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
version="2.5">
<servlet>
<servlet-name>SimpleServlet</servlet-name>
<servlet-class>test0.SimpleServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>SimpleServlet</servlet-name>
<url-pattern>/GetAddress</url-pattern>
</servlet-mapping>
</web-app>
xml的路径:D:\java\eclips\ch01\ch02\WEB-INF\web.xml
请高手帮忙指点下,非常感谢!
HTTP Status 404 - /ch02/SimpleServlet--------------------------------------------------------------------------------type Status reportmessage /ch02/SimpleServletdescription The requested resource (/ch02/SimpleServlet) is not available.
--------------------------------------------------------------------------------Apache Tomcat/6.0.26我用的软件是eclipse tomcat程序如下:
package test0;import java.io.IOException;
import java.io.PrintWriter;import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;@SuppressWarnings("serial")
public class SimpleServlet 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()"+"\n");
out.println("</center></font></body>");
out.println("</html>");
out.close();
}
}
class 的路径:D:\java\eclips\ch01\ch02\WEB-INF\classes\test0\SimpleServlet.classxml代码如下:
<?xml version="1.0" encoding="ISO-8859-1"?>
<web-app xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
version="2.5">
<servlet>
<servlet-name>SimpleServlet</servlet-name>
<servlet-class>test0.SimpleServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>SimpleServlet</servlet-name>
<url-pattern>/GetAddress</url-pattern>
</servlet-mapping>
</web-app>
xml的路径:D:\java\eclips\ch01\ch02\WEB-INF\web.xml
请高手帮忙指点下,非常感谢!
解决方案 »
- 大神帮我解答~~万分感谢
- 关于Serializable id
- 关于Struts2配置两个Action直接跳转问题
- 关于页面静态 模版替代那种
- 请教 500错误解决方法
- java.lang.IllegalStateException: Failed to load ApplicationContext
- 请问 我想用JSP连ACCESS 请问连接代码怎么写 需要驱动吗?
- 急:jdk,jswdk安装成功,能打开默认页,但不能运行JSP页面
- 怎样把数据库中的记录些到下拉列表框中,很复杂,我只能写进一个去,请问怎么写?谢谢,在线等待!
- 如果微软继续跟进Java,他们迟早会把它消灭掉,而Java其实不过是Windows和Internet之战的牺牲品
- AJAX实现三级目录问题
- 存储过程返回结果集 取值问题? 急
<?xml version="1.0" encoding="ISO-8859-1"?>
<web-app xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
version="2.5">
<servlet>
<servlet-name>SimpleServlet</servlet-name>
<servlet-class>test0.SimpleServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>SimpleServlet</servlet-name>
<url-pattern>/GetAddress</url-pattern>//那你调用servlet就调用这个url了/GetAddress,建议一致
</servlet-mapping>
</web-app>
再就是楼上说的
<?xml version="1.0" encoding="ISO-8859-1"?>
<web-app xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
version="2.5">
<servlet>
<servlet-name>SimpleServlet</servlet-name>
<servlet-class>test0.SimpleServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>SimpleServlet</servlet-name>
<url-pattern>/GetAddress</url-pattern>//那你调用servlet就调用这个url了/GetAddress,建议一致
</servlet-mapping>
</web-app>
在IE中访问:
http://localhost:8080/项目名/GetAddress.do
就OK了!