首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > JAVA > Java Web开发 >

jsp页面提交数据! 急该如何处理

2012-01-02 
jsp页面提交数据!! 急!!!各位大哥:小弟刚学不久,先遇到一个问题,请帮帮忙。我在一个jsp页面作了一个多选。提

jsp页面提交数据!! 急!!!
各位大哥:
                  小弟刚学不久,   先遇到一个问题,请帮帮忙。
                  我在一个jsp页面作了一个多选。提交按钮用的是图片,这些多选项都是从数据库里面调出来的,   然后让客户选择提交,(xiao。jsp   他的配置文件是ctrlxiao。java   查询数据和提交都在这个java里面实现)   我把提交的内容也提交到这个java   上。   但是为什么提交的时候总是执行2次呢!!   代码如下:

public   class   CtrlXdc   extends   Dispatcher   {

  public   void   dispatcher(HttpServletRequest   request,   HttpServletResponse   response)
      {

            //读取当前方法
            String   Page=Req.getPara(request, "page ");
            //网页加速功能
            String   webpagePath=admin.Lib.getStaticWebpagePath(request);
            if(webpagePath!=null   &&   !webpagePath.equals( " ")){   forward(request,response,webpagePath);   return;}
            //初始化系统(基本参数,配置参数,数据库连接参数)
            Lib.init(request);     //该函数中的ValidateUser(request)比较慢,以后再决定如何优化
            DAO   dao=new   DAO();
            request.setAttribute( "dao ",dao);     //写到request中,系统就能自动关闭dao对象
            //根据不同的方法调用不同的功能
            if(Page.equals( "update_action ")){   actAction(dao,request,response);   return;}
            //actAction(   dao,   request,   response);
            if(Page.equals( " "))   xdc(dao,request,response);
            //转到显示层
            forward(request,   response, "/channel/xdc.jsp ");
      }

  public   void   xdc(DAO   dao,HttpServletRequest   request,   HttpServletResponse   response)
      {
            //业务逻辑处理            
            request.setAttribute( "websiteLeftXWHD "         ,Lib.GetLinkConetnt(dao, "music.website.leftxwhd "));           //相关下载频道的左侧页面

            Map   map=getAnswerMap(dao);
            request.setAttribute( "questionMap ",   map);
          ArrayList   list4=(map!=null?getOption(dao,map.get( "id ").toString()):null);
              request.setAttribute( "arrOptions ",list4);
      }
       

        //获得在线调查问题名
        public   static   Map   getAnswerMap   (DAO   dao){
                String   sql   =   "select   id   from   tbtool_question   where   is_visible=1   and   is_over=0   and   issuance=1   order   by   id   desc   limit   1 ";
                String   id     =   dao.conValue(sql);


                Map   questionMap     =   dao.conRow( "select   *   from   tbtool_ques_item   where   is_need=1   and   question_id= ' "+id+ " '   order   by   id   desc   limit   1 ");
                return   questionMap;
        }
        //获得在线调查选项
        public   static   ArrayList   getOption   (DAO   dao,String   answerId){
                ArrayList   arrOptions=   dao.conList( "select   *   from   tbtool_ques_option   where   item_id= ' "+answerId+ " ' ");
                return   arrOptions;
        }

        public   void   actAction(DAO   dao,HttpServletRequest   request,   HttpServletResponse   response)
        {
        System.out.println( "dddddddd ");
        String   action=Req.getPara(request, "action ");
          String   []   result   =   request.getParameterValues( "test ");
        String   sql= " ";
        int   errcode;
        int   j=0;
        if(action.equals( "update ")){
        //int   count=Integer.parseInt(Req.getPara(request, "count "));
                        String   idList= " ";
                        //System.out.print( "12313316554 ");
                        for(int   i=0;i <result.length;i++){
                        j=Integer.parseInt(result[i]);
                            /*   if(!Req.getPara(request, "chk "+i).equals( " ")   &&   Req.getPara(request, "chk "+i)!=null)
                              idList=idList+ ", "+Req.getPara(request, "result[i] ");
                        }                      
                      idList=idList.substring(0);*/
                       
                        sql= "update   tbtool_ques_option   set   clicks=clicks+1   where   id= ' "+j+ " ' ";
                        errcode=dao.conExec(sql);
               
                        }
       
        }


}
}


jsp页面:
<form   method= "POST "   action= " "   target=_edit>              
                <tr>
                    <td   colspan= "3 "> <img   src= "image/diaocha1.gif "   width= "153 "   height= "20 "   /> </td>
                </tr>
                <tr>
                    <td   width= "8 "   background= "image/bg-zhuangtai.gif ">   </td>
                    <td   width= "137 "   height= "38 "   valign= "top "   bgcolor= "#2986b1 "> <table   width= "131 "   border= "0 "   align= "center "   cellpadding= "0 "   cellspacing= "0 ">
                            <tr>
                                <td   height= "130 "   bgcolor= "#d6f5ff "> <table   width= "100% "   border= "0 "   cellspacing= "0 "   cellpadding= "0 "   class= "index7 ">
                    <tr>
                        <td   >   <%=questionMap.get( "content ")%> </td>
                    </tr>    
    <tr>
                          <td   >
                    <%for(int   index=0;arrOptions!=null&&index <arrOptions.size();index++){
                      Map     map=(Map)arrOptions.get(index);%>
                      <input   type= "hidden "   name= "count "   value= " <%=index%> "   >
                                                        <input   type= " <%if(questionMap.get( "item_type ").toString().equals( "1 ")){out.print( "radio ");}else{out.print( "checkbox ");}%> "   name= "test "   value= " <%=map.get( "id ").toString()%> "   /> <%=map.get( "content ").toString()%> <br>
                                                      <%}   %>
</td>
    </tr>    
                </table> </td>
                            </tr>


                    </table> </td>
                    <td   width= "8 "   background= "image/bg-zhuangtai1.gif ">   </td>
                </tr>
                <tr>
                    <td   height= "37 "   colspan= "3 "   align= "center "   valign= "top "   background= "image/diaocha2.gif "> <table   width= "100% "   border= "0 "   cellspacing= "0 "   cellpadding= "0 ">
                            <tr>
                                <td   height= "35 "   align= "center ">
                                <input   type= "image "   src= "image/tijiao.gif "   width= "50 "   height= "23 "   onclick= "javascript:this.form.action= ' <%= "/channel/xdc.do "+ "?page= "+gloActionPage+ "&action=update "%> ';this.form.submit(); "   /> &nbsp;  
                                <a   href= "diaocha.do "   target= "_black "> <img   src= "image/chakan.gif "   width= "50 "   height= "23 "   border= "0 "/> </a>
                                </td>
                            </tr>
                    </table> </td>
                </tr>
    </form>

那为大哥可以仔细的说说啊!!   如何做啊?

[解决办法]
<input type= "image " src= "image/tijiao.gif " width= "50 " height= "23 " onclick= "javascript:this.form.action= ' <%= "/channel/xdc.do "+ "?page= "+gloActionPage+ "&action=update "%> ';this.form.submit(); " /> 的onclick要么是javascript:this.form.action= ' <%= "/channel/xdc.do "+ "?page= "+gloActionPage+ "&action=update "%> ',要么是this.form.submit(),只能要一个就可以了
[解决办法]
同上
[解决办法]
up
[解决办法]
同上上
[解决办法]
<form method= "POST " action= " " target= "_blank ">

热点排行