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 reportmessage HTTP method GET is not supported by this URLdescription The specified HTTP method is not allowed for the requested resource (HTTP method GET is not supported by this URL).这样的错误提示,请教高手指点一下。。或者指点下应该怎么修改?
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 reportmessage HTTP method GET is not supported by this URLdescription The specified HTTP method is not allowed for the requested resource (HTTP method GET is not supported by this URL).这样的错误提示,请教高手指点一下。。或者指点下应该怎么修改?
throws ServletException, IOException {
doPost(req, resp);
}加上这个方法试试
看错误描述来看应该是发送的get请求,所以处理不了。
<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方法的。。