<servlet> <servlet-name>MyName</servlet-name> <servlet-class>mypackage.MyServlet</servlet-class> </
packagecoreservlets;importjava.io.*;importjavax.servlet.*;importjavax.servlet.http.*;...
package coreservlets;
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
/**
* <P>
* Taken from Core Servlets and JavaServer Pages Volume II
* from Prentice Hall and Sun Microsystems Press,
* http://volume2.coreservlets.com/.
* (C) 2007 Marty Hall, Larry Brown, and Yaakov Chaikin;
* may be freely used or adapted.
*/
public class TestServlet extends HttpServlet {
public void doGet(HttpServletRequest request,
HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html");
PrintWriter out = response.getWriter();
String docType =
"<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0 " +
"Transitional//EN\">\n";
out.println
(docType +
"<HTML>\n" +
"<HEAD><TITLE>Servlet Test</TITLE></HEAD>\n" +
"<BODY BGCOLOR=\"#FDF5E6\">\n" +
"<H1>Servlet Test</H1>\n" +
"URL you used: " + request.getRequestURL() + "\n" +
"</BODY></HTML>");
}
} 展开
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
/**
* <P>
* Taken from Core Servlets and JavaServer Pages Volume II
* from Prentice Hall and Sun Microsystems Press,
* http://volume2.coreservlets.com/.
* (C) 2007 Marty Hall, Larry Brown, and Yaakov Chaikin;
* may be freely used or adapted.
*/
public class TestServlet extends HttpServlet {
public void doGet(HttpServletRequest request,
HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html");
PrintWriter out = response.getWriter();
String docType =
"<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0 " +
"Transitional//EN\">\n";
out.println
(docType +
"<HTML>\n" +
"<HEAD><TITLE>Servlet Test</TITLE></HEAD>\n" +
"<BODY BGCOLOR=\"#FDF5E6\">\n" +
"<H1>Servlet Test</H1>\n" +
"URL you used: " + request.getRequestURL() + "\n" +
"</BODY></HTML>");
}
} 展开
3个回答
展开全部
截图异常消息可知
description :有一个内部阻止该请求
exception :TestServlet实例化错误
rootcause :类找不到异常,找不到TestServlet
从你Servlet类估计看不出什么异常,可能是你XML配置写错了,或者你请求的JSP页面的Action写错了。
XML的代码如下
<servlet>
<servlet-name>MyName</servlet-name>
<servlet-class>mypackage.MyServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>Myname</servlet-name>
<url-pattern>/myAction</url-pattern>
</servlet-mapping>
jsp页面的action要这样写
<form action = "myAction" method="post"> 或者
<form action = "/projectName/myAction" method="post">
(注:projectName是你的工程名称)
description :有一个内部阻止该请求
exception :TestServlet实例化错误
rootcause :类找不到异常,找不到TestServlet
从你Servlet类估计看不出什么异常,可能是你XML配置写错了,或者你请求的JSP页面的Action写错了。
XML的代码如下
<servlet>
<servlet-name>MyName</servlet-name>
<servlet-class>mypackage.MyServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>Myname</servlet-name>
<url-pattern>/myAction</url-pattern>
</servlet-mapping>
jsp页面的action要这样写
<form action = "myAction" method="post"> 或者
<form action = "/projectName/myAction" method="post">
(注:projectName是你的工程名称)
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
抱歉!这个问题不懂哦,请再加油吧!
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
抱歉!这个问题不懂哦,请再加油吧!
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询