HTTP method GET is not supported by this URL
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).
这样的错误提示,请教高手指点一下。。
或者指点下应该怎么修改?