HTTP Status 405 - HTTP method POST is not supported by this URL
当我使用以下代码(如下)时出现错误......导致问题的行(显然)是getServletContext().getRequestDispatcher("/EditObject?id="+objId).forward(request, response);
package web.objects;
import java.io.IOException;
import java.sql.SQLException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import dao.ObjDetailsDao;
@SuppressWarnings("serial")
public class EditObjectText extends HttpServlet {
public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
int objId = Integer.parseInt(request.getParameter("objId"));
String text = (String)request.getParameter("description");
ObjDetailsDao oddao = new ObjDetailsDao();
try {
oddao.modifyText(text, objId);
/////////////
getServletContext().getRequestDispatcher("/EditObject?id="+objId).forward(request, response);
////////////
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (ServletException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
编辑:我throws ServletException, IOException
按照建议添加了,但这并没有改变错误。
编辑:EditObject servlet 看起来像这样
@SuppressWarnings("serial")
public class EditObject extends HttpServlet{
public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
int objId = Integer.parseInt(request.getParameter("id"));
dispPage(objId, request, response);
}
private void dispPage(int objId, HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException{
// ... lots of code in here
getServletContext().getRequestDispatcher("/jsp/objectPageEdit.jsp").forward(request, response);
}
}
另一个编辑:所以基本上我不能做我正在做的事情。我需要的是,用户提交一个发布请求,然后我将他/她引回一个使用 Get 方法而不是 Post 的 servlet。如何在不收到错误的情况下进行此推荐?提前致谢。