遇到一个关于post的问题
下面是我运行页面显示的errormessage: HTTP method POST is not supported by this URL
description: The specified HTTP method is not allowed for the requested resource (HTTP method POST is not supported by this URL).
(1)下面是数据库更新的代码
程序代码:
port java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import bean.CtrlSql;
public class ModifyStuServlet extends HttpServlet{
private static final long seriaVersionUID=1L;
public void doGet(HttpServletRequest request,HttpServletResponse response)
throws ServletException,IOException{
response.setContentType("text/html");
CtrlSql con=new CtrlSql();//实例化数据库处理类
String stu_id=request.getParameter("stu_id");
String stu_name=
new String(request.getParameter("name").getBytes("iso8859-1"));
//获得客户端提交的name,并对期重新编码防止中文乱码
int age=Integer.parseInt(request.getParameter("age"));
String sex=
new String(request.getParameter("sex").getBytes("iso8859-1"));
//获得客户端提交的sex,并对期重新编码防止中文乱码
String tel= request.getParameter("tel");
String zhuanye=
new String(request.getParameter("zhuanye").getBytes("iso8859-1"));
String yuanxi=
new String(request.getParameter("yuanxi").getBytes("iso8859-1"));
String sql="update stuinfo set stu_name='"+stu_name+"',age="+age+",sex='"+sex+"',tel='"+tel+"',zhuanye='"+zhuanye+"',yuanxi='"+yuanxi+"' where stu_id='"+stu_id+"'";
con.con();//连接到数据库
con.update(sql);//更新数据库
response.sendRedirect("../iframe/stu_info.jsp");
//页面转到stu_info.jsp
}
public void dopost(HttpServletRequest request,HttpServletResponse response)
throws ServletException,IOException{
doGet(request,response);
}
}
(2)web.xml文件配置import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import bean.CtrlSql;
public class ModifyStuServlet extends HttpServlet{
private static final long seriaVersionUID=1L;
public void doGet(HttpServletRequest request,HttpServletResponse response)
throws ServletException,IOException{
response.setContentType("text/html");
CtrlSql con=new CtrlSql();//实例化数据库处理类
String stu_id=request.getParameter("stu_id");
String stu_name=
new String(request.getParameter("name").getBytes("iso8859-1"));
//获得客户端提交的name,并对期重新编码防止中文乱码
int age=Integer.parseInt(request.getParameter("age"));
String sex=
new String(request.getParameter("sex").getBytes("iso8859-1"));
//获得客户端提交的sex,并对期重新编码防止中文乱码
String tel= request.getParameter("tel");
String zhuanye=
new String(request.getParameter("zhuanye").getBytes("iso8859-1"));
String yuanxi=
new String(request.getParameter("yuanxi").getBytes("iso8859-1"));
String sql="update stuinfo set stu_name='"+stu_name+"',age="+age+",sex='"+sex+"',tel='"+tel+"',zhuanye='"+zhuanye+"',yuanxi='"+yuanxi+"' where stu_id='"+stu_id+"'";
con.con();//连接到数据库
con.update(sql);//更新数据库
response.sendRedirect("../iframe/stu_info.jsp");
//页面转到stu_info.jsp
}
public void dopost(HttpServletRequest request,HttpServletResponse response)
throws ServletException,IOException{
doGet(request,response);
}
}
程序代码:
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5"
xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
<servlet>
<servlet-name>ModifyStuServlet</servlet-name>
<servlet-class>servlet.ModifyStuServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>ModifyStuServlet</servlet-name>
<url-pattern>/servlet/ModifyStuServlet</url-pattern>
</servlet-mapping>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
(3)修改页面的信息的代码<web-app version="2.5"
xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
<servlet>
<servlet-name>ModifyStuServlet</servlet-name>
<servlet-class>servlet.ModifyStuServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>ModifyStuServlet</servlet-name>
<url-pattern>/servlet/ModifyStuServlet</url-pattern>
</servlet-mapping>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
程序代码:
<%@ page language="java" pageEncoding="gb2312"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<jsp:useBean id="con" class="bean.CtrlSql"></jsp:useBean>
<%@ page import ="java.sql.ResultSet"%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8"/>
<title>修改学生信息页面</title>
<style type="text/css">
table{
width:100%;
font-size:12px;
color:#333333;
border-collapse:collapse;
text-align:left;
}
th,td{
padding:3px;
border-bottom:1px solid #bbb;
padding:10px;
}
thead tr{
font-size:14px;
height:58px;
color:#666;
background-color:#ECECEC;
border:none;
}
thead th;hover {
background-color:#D4E0F2;
}
.textInput{
width:150px;
height:20px;
border:1px solid #58805f;
line-height:21px;
}
select option{
background-color:#D4E0F2;
}
.submitButton{
width:100px;
height:25px;
margin-top:20px;
margin-left:186px;
font-size:12px;
font-weight:bold;
border:2px solid #D4E0F2;
border-right-color: #58805f;
border-bottom-color:#58805f;
background-color:#DE0F2;
color:#666666;
}
</style>
</head>
<body style="margin-top:0px";>
<form action="../servlet/ModifyStuServlet" method="post">
<table>
<thead>
<tr>
<th colspan="2">学生信息修改</th>
</tr>
</thead>
<%
String stu_id=request.getParameter("stu_id");
String sql="select *from stuinfo where stu_id='"+stu_id+"'";
con.con();
ResultSet rs=con.query(sql);
rs.next();
%>
<tbody>
<tr>
<th> 学号</th>
<td>
<input name="stu_id" type="text" readonly="readonly"
class="textInput" value="<%=rs.getString(1)%> "/>
<font color="red">学号不能修改</font>
</td>
</tr>
<tr>
<th>姓名:</th>
<td>
<input name="name" type="text" class="textInput"
value="<%=rs.getString(2)%>"/>
</td>
</tr>
<tr>
<th>年龄:</th>
<td>
<input name="age" type="text" class="textInput"
value="<%=rs.getString(3)%>"/>
</td>
</tr>
<tr>
<th>性别:</th>
<td>
<input name="sex" type="text" class="textInput"
value="<%=rs.getString(4)%>"/>
</td>
</tr>
<tr>
<th>电话:</th>
<td>
<input name="tel" type="text" class="textInput"
value="<%=rs.getString(5)%>"/>
</td>
</tr>
<tr>
<th>专业:</th>
<td>
<input name="zhuanye" type="text" class="textInput"
value="<%=rs.getString(6)%>"/>
</td>
</tr>
<tr>
<th>院系:</th>
<td>
<input name="yuanxi" type="text" class="textInput"
value="<%=rs.getString(7)%>"/>
</td>
</tr>
</tbody>
</table>
<input type="submit" name="submit" value="提交" class="submitButton"/>
</form>
</body>
</html>
请大家帮个忙看一下,谢谢了。。<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<jsp:useBean id="con" class="bean.CtrlSql"></jsp:useBean>
<%@ page import ="java.sql.ResultSet"%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8"/>
<title>修改学生信息页面</title>
<style type="text/css">
table{
width:100%;
font-size:12px;
color:#333333;
border-collapse:collapse;
text-align:left;
}
th,td{
padding:3px;
border-bottom:1px solid #bbb;
padding:10px;
}
thead tr{
font-size:14px;
height:58px;
color:#666;
background-color:#ECECEC;
border:none;
}
thead th;hover {
background-color:#D4E0F2;
}
.textInput{
width:150px;
height:20px;
border:1px solid #58805f;
line-height:21px;
}
select option{
background-color:#D4E0F2;
}
.submitButton{
width:100px;
height:25px;
margin-top:20px;
margin-left:186px;
font-size:12px;
font-weight:bold;
border:2px solid #D4E0F2;
border-right-color: #58805f;
border-bottom-color:#58805f;
background-color:#DE0F2;
color:#666666;
}
</style>
</head>
<body style="margin-top:0px";>
<form action="../servlet/ModifyStuServlet" method="post">
<table>
<thead>
<tr>
<th colspan="2">学生信息修改</th>
</tr>
</thead>
<%
String stu_id=request.getParameter("stu_id");
String sql="select *from stuinfo where stu_id='"+stu_id+"'";
con.con();
ResultSet rs=con.query(sql);
rs.next();
%>
<tbody>
<tr>
<th> 学号</th>
<td>
<input name="stu_id" type="text" readonly="readonly"
class="textInput" value="<%=rs.getString(1)%> "/>
<font color="red">学号不能修改</font>
</td>
</tr>
<tr>
<th>姓名:</th>
<td>
<input name="name" type="text" class="textInput"
value="<%=rs.getString(2)%>"/>
</td>
</tr>
<tr>
<th>年龄:</th>
<td>
<input name="age" type="text" class="textInput"
value="<%=rs.getString(3)%>"/>
</td>
</tr>
<tr>
<th>性别:</th>
<td>
<input name="sex" type="text" class="textInput"
value="<%=rs.getString(4)%>"/>
</td>
</tr>
<tr>
<th>电话:</th>
<td>
<input name="tel" type="text" class="textInput"
value="<%=rs.getString(5)%>"/>
</td>
</tr>
<tr>
<th>专业:</th>
<td>
<input name="zhuanye" type="text" class="textInput"
value="<%=rs.getString(6)%>"/>
</td>
</tr>
<tr>
<th>院系:</th>
<td>
<input name="yuanxi" type="text" class="textInput"
value="<%=rs.getString(7)%>"/>
</td>
</tr>
</tbody>
</table>
<input type="submit" name="submit" value="提交" class="submitButton"/>
</form>
</body>
</html>
搜索更多相关主题的帖子:
数据库 requested specified import method
----------------解决方案--------------------------------------------------------
怎么将页面修改的信息不能在数据库中反映出来,并且在页面修改上也反映不出来。求帮助啊、、。、、、
----------------解决方案--------------------------------------------------------
我将dopost改回doPost后,在调转到页面后出现java.sql.SQLException: Can not issue data manipulation statements with executeQuery(). 求帮助、、、、
----------------解决方案--------------------------------------------------------
把sql语句打印出来到数据库里边执行下看看就知道问题出在哪里了
----------------解决方案--------------------------------------------------------