有关servlet的问题
我的servlet编译成功了,我把这个类拷到了Tomcat1.4的目录下面
但是我运行Tomcat1.4时怎么说我编译错误啊?
我的servle代码如下:
package test;
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public class Test extends HttpServlet {
protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
PrintWriter out=response.getWriter();
out.println( " <html> <body> <h1> This is a servlet test. </h1> </body> </html> ");
out.flush();
}
}
我的文件是这样放的:
Tomcat1.4---->
webapps---->
myapp--->
WEB-INF--->
classes web.xml
类放在calsses中新建的文件夹test中, 我的web.xml 文件内容如下:
<?xml version= "1.0 " encoding= "ISO-8859-1 "?>
<!DOCTYPE web-app
PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN "
"http://java.sun.com/dtd/web-app_2_3.dtd ">
<web-app>
<display-name> A application for test </display-name>
<description>
A application for test
</description>
<servlet>
<servlet-name> Test </servlet-name>
<display-name> Test </display-name>
<description> A test Servlet </description>
<servlet-class> test.Test </servlet-class>
</servlet>
<servlet-mapping>
<servlet-name> Test </servlet-name>
<url-pattern> /Test </url-pattern>
</servlet-mapping>
</web-app>
错误内容提示:
type Status report
message Servlet Test is currently unavailable
description The requested service (Servlet Test is currently unavailable) is not currently available.
[解决办法]
public class Test extends HttpServlet {
protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setContentType( "text/html "); //加这个看看
PrintWriter out=response.getWriter();
out.println( " <html> <body> <h1> This is a servlet test. </h1> </body> </html> ");
out.flush();
}
}
[解决办法]
Test类有没放到包test下面呢?还有检查一下web.xml中的配置有否疏漏
[解决办法]
注意一下大小写
[解决办法]
你请求SERVLET的HTML或者JSP页面怎么写的,贴出来看看
[解决办法]
第一检查SERVLET类是否存在,第二检查web.xml中SERVLET的配置
[解决办法]
你重新编译一下试试吧。
我可以运行你的程序的。