初学Tomcat7 部署servletde 的简单问题
type Status report
message /ch03/welecome
description The requested resource (/ch03/welecome) is not available.
出现这样的错误!
web.xml 配置
<servlet>
<servlet-name>MyWelecomeServlet</servlet-name>
<servlet-class>WelecomeServlet</servlet-class>
<init-param>
<param-name>greeting</param-name>
<param-value>Welecome you</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>MyWelecomeServlet</servlet-name>
<url-pattern>/welecome</url-pattern>
</servlet-mapping>
servlet 代码:
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 WelecomeServlet extends HttpServlet
{
private String greeting;
public void Init()
{
greeting = getInitParameter("greeting");
}
public void doGet(HttpServletRequest req, HttpServletResponse resp)
throws
ServletException,
IOException
{
req.setCharacterEncoding("gb2312");
String username = req.getParameter("username");
String welecomeInfo = greeting + ", " + username;
resp.setContentType("text/html");
PrintWriter out = resp.getWriter();
out.println("");
out.println("");
out.println(welecomeInfo);
out.println("");
out.close();
}
public void doPost(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException
{
doGet(req, resp);
}
}
welecome.html代码
<html>
<title> 我的第一个get方法servlet程