HTTP method GET is not supported by this URL

zbz4785 2009-04-10 01:57:46
package shop;

import java.io.IOException;
import java.util.Vector;

import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

public final class IndexServlet extends HttpServlet{
//构造函数,调用init方法
public IndexServlet(){
super();
}
public void init(ServletConfig config) throws ServletException {
super.init(config);
}

protected void doPost(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException {
// TODO Auto-generated method stub
DB db=new DB();
shop sp=new shop(); //具体业务处理的Javabean
Vector sortList = null;
Vector timeProductList=null;
Vector countProductList=null;

try {
sortList = sp.getSorts(db);
timeProductList = sp.getTopProducts(db, 1);
countProductList = sp.getTopProducts(db, 2);
} catch (Exception e) {
// TODO: handle exception
e.printStackTrace();
}
HttpSession session=req.getSession();
if(session==null){
System.out.println("no session");
System.exit(1);
}
try {
//设置图书种类会话属性
session.setAttribute(Constants.SORT_LIST_KEY, sortList);
//设置图书上架时间会话属性
session.setAttribute(Constants.TIME_PRODUCT_LIST_KEY,
timeProductList);
//设置图书数量会话属性
session.setAttribute(Constants.COUNT_PRODUCT_LIST_KEY,
countProductList);
} catch (Exception e) {
// TODO: handle exception
e.printStackTrace();
}
db.close();
String target="/index.jsp";
resp.sendRedirect(target);
}

}

网上别人说的是重写 doPost或doGet,我的servlet中重写了doPost,但是为什么还是会出现 :

type Status report

message HTTP method GET is not supported by this URL

description The specified HTTP method is not allowed for the requested resource (HTTP method GET is not supported by this URL).

这样的错误提示,请教高手指点一下。。

或者指点下应该怎么修改?
...全文
538 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
zbz4785 2009-04-10
  • 打赏
  • 举报
回复
jsp中是用post方法调用的。。我的是一个index.jsp.用的框架,,

index.jsp

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Frameset//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd">
<html >
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>网上书店</title>
</head>

<frameset rows="110,*,63" cols="*" framespacing="0" frameborder="no" border="0" bordercolor="#33FF00">
<frame src="top.html" name="topFrame" scrolling="no" noresize="noresize" id="topFrame" title="topFrame" />
<frameset rows="*" cols="183,*" framespacing="0" frameborder="no" border="0">
<frame src="left.jsp" name="leftFrame" scrolling="no" noresize="noresize" id="leftFrame" title="leftFrame" />
<frame src="main.jsp" name="mainFrame" id="mainFrame" title="mainFrame" />
</frameset>
<frame src="bottom.html" scrolling="no">
</frameset>
<noframes><body>
<p>此网页使用了框架,但您的浏览器不支持框架。</p>
</body>
</noframes></html>

这是left.jsp的调用post方法的地方;;

<FORM action="Search_servlet" method="post" target="mainFrame">

其他三个网页都没有调用post或者get方法的。。

feiling111222 2009-04-10
  • 打赏
  • 举报
回复
因为你的请求是GET,但是你没写GET请求,1楼的对
jinchun1234 2009-04-10
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 zl_bright 的回复:]
protected void doGet(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException {
doPost(req, resp);
}

加上这个方法试试
[/Quote]
ouyangxiaokang6 2009-04-10
  • 打赏
  • 举报
回复
jsp怎么写的,贴出来。看看里面是不是用get方法提交的。
zbz4785 2009-04-10
  • 打赏
  • 举报
回复
加了还是一样的结果。。
hushuang840513 2009-04-10
  • 打赏
  • 举报
回复
应该是提交请求的方式不对,你只重写了doPost,所以只能处理post请求。
看错误描述来看应该是发送的get请求,所以处理不了。
j2eeoriented 2009-04-10
  • 打赏
  • 举报
回复
在doget 里调用一下dopost
台城柳月 2009-04-10
  • 打赏
  • 举报
回复
protected void doGet(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException {
doPost(req, resp);
}

加上这个方法试试

81,092

社区成员

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

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