JSP调Servlet问题,求高手解答,,谢谢(d)

HCLY 2005-10-25 02:43:31
我的JSP页面访问不到servlet,访问就报404错误,说页面不存在
hello.jsp

<%@ page contentType="text/html; charset=GBK" %>
<html>
<head>
<title>
hello
</title>
</head>
<body bgcolor="#ffffff">
<h1>
JBuilder Generated JSP
</h1>
<form method="post" action="/testServlet">
<br><br>
<input type="submit" name="Submit" value="Submit">

</form>
</body>
</html>


servelt

package jspservlet;

import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
import java.util.*;



public class TestServlet extends HttpServlet {
private static final String CONTENT_TYPE = "text/html; charset=GBK";

public void init() throws ServletException {
}


public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
response.setContentType(CONTENT_TYPE);
String userName= request.getParameter("user");
PrintWriter out = response.getWriter();
out.println("<html>");
out.println("<head><title>TestServlet</title></head>");
out.println("<body bgcolor=\"#ffffff\">");
out.println("<p>The servlet has received a GET. This is the reply.</p>");
out.println("<i>"+userName+"</i><br>");
out.println("</body></html>");

}

public void destroy() {
}
}

web.xml


<?xml version="1.0" encoding="UTF-8"?>
<!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>
<servlet>
<servlet-name>testservlet</servlet-name>
<servlet-class>jspservlet.TestServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>testservlet</servlet-name>
<url-pattern>/testservlet</url-pattern>
</servlet-mapping>
</web-app>

...全文
180 15 打赏 收藏 转发到动态 举报
写回复
用AI写文章
15 条回复
切换为时间正序
请发表友善的回复…
发表回复
shine333 2005-10-25
  • 打赏
  • 举报
回复
<form method="post" action="<%= request.getContextPath() %>/testServlet">
andyao 2005-10-25
  • 打赏
  • 举报
回复
1. action="testservlet"是相对目录,访问
http://localhost:8080/JspServletapp/testservlet

2. action="/testservlet"是绝对目录, 访问
http://localhost:8080/testservlet

搂住写成了绝对目录所以报错,可以改成相对目录或者
action="/JspServletapp/testservlet"
都可以访问
believefym 2005-10-25
  • 打赏
  • 举报
回复
JspServletapp/TestServlet
或者JspServletapp/jspservlet/TestServlet
或者其他的情况,看web.xml怎么写了

不是让你贴web.xml了吗?
sunning1929 2005-10-25
  • 打赏
  • 举报
回复
action="testservlet"
HCLY 2005-10-25
  • 打赏
  • 举报
回复
还是不行啊,郁闷啊,,
请指点
sunning1929 2005-10-25
  • 打赏
  • 举报
回复
可以了没有
HCLY 2005-10-25
  • 打赏
  • 举报
回复
我用
http://localhost:8080/JspServletapp/hello.jsp
访问JSP页面
可是一访问servlet页面地址就变成
http://localhost:8080/testservlet
怎么servlet不成servlet上下文中了?
sunning1929 2005-10-25
  • 打赏
  • 举报
回复
重启一下服务试试
sunning1929 2005-10-25
  • 打赏
  • 举报
回复
action="/testservlet"
s小写
believefym 2005-10-25
  • 打赏
  • 举报
回复
没改嘛
你把web.xml贴出来看看
HCLY 2005-10-25
  • 打赏
  • 举报
回复
地址不可能输错啦,我从JSP页面调的servlet
HCLY 2005-10-25
  • 打赏
  • 举报
回复
把form method="post" action="/testServlet">
改成form method="post" action="/testservlet">
还是不行,,
believefym 2005-10-25
  • 打赏
  • 举报
回复
也许你的web.xml的servlet url pattern跟页面的action地址没匹配好
Mark_MaoHUA 2005-10-25
  • 打赏
  • 举报
回复
服务器没有配置好,或者地址输错了?
HCLY 2005-10-25
  • 打赏
  • 举报
回复
d求高手指点,,谢谢

62,629

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧