请教一下为什么我doPost 和 doGet 方法都写了 却显示 "此URL不支持Http方法POST"。

Zvoon 2020-12-18 03:31:06
package servlet;

import Tools.DBUtils;
import com.Student;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.sql.SQLException;
import java.util.List;

public class XiuGaiServlet extends HttpServlet {
@Override
protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
req.setCharacterEncoding("utf-8");
Student stu = new Student();
stu.setMingzi(req.getParameter("mingzi"));
stu.setDizhi(req.getParameter("dizhi"));
stu.setYuwen(req.getParameter("yuwen"));
stu.setShuxue(req.getParameter("shuxue"));
stu.setYingyu(req.getParameter("yingyu"));
try {
boolean ok = new DBUtils().xiugai(stu);
if (ok){
resp.sendRedirect("sousuo");
}
} catch (SQLException throwables) {
throwables.printStackTrace();
}
}

@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
req.setCharacterEncoding("utf-8");
String id = req.getParameter("Id");
try {
List<Student> list = new DBUtils().sousuoId(id);
if (list != null){
req.setAttribute("xinxi",list);
req.getRequestDispatcher("xiugai.jsp").forward(req,resp);
}else{
req.setAttribute("cuowu","no");
resp.setContentType("text/html;charset=utf-8");
req.getRequestDispatcher("sousuo.jsp").forward(req,resp);
}
} catch (SQLException throwables) {
throwables.printStackTrace();
}
}
}





//表单如下
<form action="xiuGai" method="post">
<table border="1px" align="center" >
<tr >
<td>ID</td>
<td><input type="text" value="${xinxi.get(0).getID()}" name="Id" readonly></td>
</tr>
<tr >
<td>姓名</td>
<td><input type="text" value="${xinxi.get(0).getMingzi()}" name="mingzi"></td>
</tr>
<tr>
<td>地址</td>
<td><input type="text" value="${xinxi.get(0).getDizhi()}" name="dizhi"></td>
</tr>
<tr>
<td>语文</td>
<td><input type="text" value="${xinxi.get(0).getYuwen()}" name="yuwen"></td>
</tr>
<tr>
<td>数学</td>
<td><input type="text" value="${xinxi.get(0).getShuxue()}" name="shuxue"></td>
</tr>
<tr>
<td>英语</td>
<td><input type="text" value="${xinxi.get(0).getYingyu()}" name="yingyu"></td>
</tr>
<input type="submit">
</table>
</form>
...全文
771 点赞 收藏 回复
写回复
回复
切换为时间正序
请发表友善的回复…
发表回复

还没有回复,快来抢沙发~

发动态
发帖子
跨浏览器开发
创建于2010-06-28

5004

社区成员

解读Web 标准、分析和讨论实际问题、推动网络标准化发展和跨浏览器开发进程,解决各种兼容性问题。
申请成为版主
社区公告
暂无公告