这个问题困扰我n天了,各位大哥帮忙啊(真诚地请求)
AI牛 2004-02-13 11:09:10 我在JSP文件中想上传几个参数给Servlet,我在Jbuilder中将WebApp打包后,放到
TomCat 上,用Jsp调用Servlet时总是报错说找不到该Servlet。我把代码贴出来了,各位帮帮忙看怎么解决。
真诚
下面是Jsp文件:
<%@ page contentType="text/html; charset=GBK" %>
<%@ page errorPage="HomeJsp_error.jsp" %>
<html>
<head>
<title>
HomeJsp
</title>
</head>
<body bgcolor="#fff0f0">
<h1>
welcome to here;
</h1>
<center>
<form name="newform" action="/Servlet/HandleServlet" method="GET">
<input type="text" name="qty" size="3" value=20>
<input type="hidden" name="action" value="ADD">
<input type="submit" name="Submit" value="Add to cart">
</form>
<a href="HandleServlet?id=16">Pass the parameters</a>
</center>
</body>
</html>
下面是Servlet代码:
package parpro;
import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
import java.util.*;
public class HandleServlet extends HttpServlet {
private static final String CONTENT_TYPE = "text/html; charset=GBK";
//Initialize global variables
public void init() throws ServletException {
}
//Process the HTTP Get request
public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
response.setContentType(CONTENT_TYPE);
PrintWriter out = response.getWriter();
String getPar;
String action=request.getParameter("action");
String par=request.getParameter("id");
int s=(new Integer(par)).intValue();
if(!action.equals("ADD"))
{
getPar="what you get is :"+action+"!";
}
if(par.equals("16"))
{
getPar="what you get is 16";
}
out.println("<html>");
out.println("<head><title>HandleServlet</title></head>");
out.println("<h1><%=getPar%><h1>");
out.println("<body bgcolor=\"#ffffff\">");
out.println("<p>The servlet has received a GET. This is the reply.</p>");
out.println("</body></html>");
}
//Clean up resources
public void destroy() {
}
}
下面为tomcat的报错信息:
HTTP Status 404 - /ParPro/HandleServlet
--------------------------------------------------------------------------------
type Status report
message /ParPro/HandleServlet
description The requested resource (/ParPro/HandleServlet) is not available.
--------------------------------------------------------------------------------
Apache Tomcat/5.0.14
到底是什么愿因啊?