| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 869 人关注过本帖
标题:遇到一个关于post的问题
只看楼主 加入收藏
编程2011
Rank: 2
来 自:湖南
等 级:论坛游民
帖 子:73
专家分:19
注 册:2011-3-3
结帖率:92%
收藏
已结贴  问题点数:10 回复次数:3 
遇到一个关于post的问题
下面是我运行页面显示的error
message: 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 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文件配置
程序代码:
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5"
    xmlns="http://java. xmlns:xsi="http://www. xsi:schemaLocation="http://java. http://java.
    <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)修改页面的信息的代码
程序代码:
<%@ 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>      
                             
             
                                 
                               
请大家帮个忙看一下,谢谢了。。
              
                                 
                              
搜索更多相关主题的帖子: 数据库 requested specified import method 
2011-10-28 20:53
编程2011
Rank: 2
来 自:湖南
等 级:论坛游民
帖 子:73
专家分:19
注 册:2011-3-3
收藏
得分:0 
怎么将页面修改的信息不能在数据库中反映出来,并且在页面修改上也反映不出来。求帮助啊、、。、、、
2011-10-29 17:27
编程2011
Rank: 2
来 自:湖南
等 级:论坛游民
帖 子:73
专家分:19
注 册:2011-3-3
收藏
得分:0 
我将dopost改回doPost后,在调转到页面后出现java.sql.SQLException: Can not issue data manipulation statements with executeQuery(). 求帮助、、、、
2011-10-29 17:41
luoweijun
Rank: 3Rank: 3
等 级:论坛游侠
帖 子:67
专家分:138
注 册:2009-6-12
收藏
得分:7 
把sql语句打印出来到数据库里边执行下看看就知道问题出在哪里了
2011-10-29 18:31
快速回复:遇到一个关于post的问题
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.036683 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved