legend_jhz 2009-01-14 16:01
浏览 225
已采纳

struts token 页面刷新提交

在一个action中具有三个方法:[code="java"]
selectall(request,response,form,mapping)(转向的页面为a.jsp,分两部分:1.具有提交功能,可以设置表单。2.用来列出已经设好的信息。),delete(request,response,form,mapping)(在a.jsp页面的列表选项删除功能提交后进行删除操作);add(request,response,form,mapping)(添加功能)
[/code]
用户登录后,先调用这个action的selectall方法进入a.jsp,我在selectall方法中设置了savetoken():
[code="java"]try {

allRecorders = crmDao.getCombototal(org);
all = crmDao.getAllCombo(currentPage, lineSize, org);
} catch (Exception e) {
e.printStackTrace();
}
saveToken(request);
[/code]
在delete方法中加入:[code="java"]if(!isTokenValid(request)){
saveToken(request);
request.setAttribute("errormessage", "套餐已经删除,不能重复删除!");
return mapping.findForward("taocanexit");
}else{
crmDao.deleteTaocan(tcid);
resetToken(request);
return selectall(mapping, form, request, response);
}
[/code]
虽然是在同一个action中,但是在跳转到a.jsp前,是先用类似于xx.do?method=selectall链接转请求的,在selectall中我已经调用了saveToken方法创建了新的令牌,然后转到a.jsp,在a.jsp中包含两部分::1.具有提交功能,可以设置表单。2.用来列出已经设好的信息。在列表信息中我点击删除的时候,[color=red][b]if(!isTokenValid(request)){//进入到这里面了[/b][/color]。在a.jsp页面中我查看源码也看到了生成的token:
[code="java"][/code]但是第一次点击就执行到if(!isTokenValid(request)){//进入到这里面了

[b]问题补充:[/b]
String token_request =request.getParameter("org.apache.struts.taglib.html.TOKEN");
//打出来看看是什么
System.out.println("token in request is:"+ token_request);
得到的是:
[color=red]token in request is:null [/color]
可是a.jsp源码里有啊:
[color=red][/color]
[b]问题补充:[/b]
[code="java"]



套餐名称: /html:text     
价格: /html:text    
计费方式: 
按年/html:option半年/html:option按季/html:option
按月/html:option按次/html:option
/html:select    
付费方式: 
预付/html:option后付/html:option
/html:select    


描述: /html:text


备注: /html:textarea





    

    <tr><td colspan="2" height="26">
      <table width="100%" background="images/ti.jpg" class="style_title" border="0" bordercolor="#0000FF">
        <tr  height="26">
            <td width="11"></td>
            <td width="75" align="center" >套餐名称</td>
            <td width="80" align="center" >计费方式</td>
            <td width="75" align="center" >套餐价格</td>
            <td width="75" align="center" >付费方式</td>
            <td width="122" align="left" >&nbsp;&nbsp;描述</td>
            <td width="130" align="left" >&nbsp;&nbsp;备注</td>
            <td width="70" align="left" >内容设置</td>
            <td width="42" align="center" >修改</td>
            <td width="46"  align="center" >删除</td>
        </tr></table></td>
    </tr>
    <tr><td colspan="2" height="180" valign="top">
      <table class="style12" border="0" bordercolor="#0000FF">
        <logic:present name="all" scope="request">
        <logic:iterate id="combo" name="all" scope="request">
        <tr height="16">
          <td width="14" align="center"><img src="images/tag.jpg" border="0"></td>
          <td width="74" >${combo.tcname}</td>
                      <td width="77" align="center">${combo.price}</td> 
                     <td width="122" align="center">${combo.tcmark}</td>
          <td width="155">&nbsp;&nbsp;${combo.comments}</td>
          <td  width="70" align="left"><a href="combowork.do?method=selectall&tcid=${combo.tcid}&TB_iframe=true&height=343&width=444" class="thickbox">套餐内容</a></td>
          <td  width="58" align="center" ><a href="comboinit.do?method=comboedit&tcid=${combo.tcid}&TB_iframe=true&height=201&width=402" class="thickbox">编辑</a>&nbsp;</td>
          <td  align="center"><a href="#" onClick="f_delete(${combo.tcid});">删除</a></td>
        </tr>
        </logic:iterate>
        </logic:present>
      </table></td>
    </tr>
            </html:form>

[/code]
[b]问题补充:[/b]
删除的时候不是提交的form,拿这个怎么改呢?
[b]问题补充:[/b]
这个能不能在js中将token传输过去,我在js中改为两个参数然后改成这样:
[code="java"]
function f_delete(id,token)
{

if(confirm('你确认要删除吗?'))
this.location.href="comboinit.do?method=delete&tcid="+id+"&org.apache.struts.taglib.html.TOKEN="+token;
}
[/code]
delete删除的时候改为:
[code="java"]
删除
[/code]
可是这样后,a.jsp源码中[color=red]${org.apache.struts.taglib.html.TOKEN}为空[/color]传不过去,如果用js传该怎么写呢?
[color=red]修改Action,然后 提交当前Form吧; [/color] 如果这样,有需要怎么改呢?谢谢!

[b]问题补充:[/b]
[code="java"]function f_delete(id,tokenId)

{

if(confirm('你确认要删除吗?'))

var token = document.getElementById(tokenId).value;

this.location.href="comboinit.do?method=delete&tcid="+id+"&org.apache.struts.taglib.html.TOKEN="+token;

}

删除 [/code]
这样传过去[color=red]'org.apache.struts.taglib.html.TOKEN'[/color]在url中显示为:
[color=red]&org.apache.struts.taglib.html.TOKEN=org.apache.struts.taglib.html.TOKEN[/color]
[b]问题补充:[/b]
谢谢[color=red]bohemia[/color],新年快乐!

  • 写回答

6条回答 默认 最新

  • bohemia 2009-01-15 10:18
    关注

    [code="java"]function f_delete(id,tokenId)

    {

    if(!confirm('你确认要删除吗?')){
    return false;
    }

    var token = document.getElementById(tokenId).value;

    alert(token);
    this.location.href="comboinit.do?method=delete&tcid="+id+"&org.apache.struts.taglib.html.TOKEN="+token;

    } [/code]

    或者

    function f_delete(id,tokenId)

    {

    if(!confirm('你确认要删除吗?')){
    return false;
    }

    document.getElementsByName(tokenId)[0].value; this.location.href="comboinit.do?method=delete&tcid="+id+"&org.apache.struts.taglib.html.TOKEN="+token;

    }

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(5条)

报告相同问题?

悬赏问题

  • ¥50 comsol稳态求解器 找不到解,奇异矩阵有1个空方程返回的解不收敛。没有返回所有参数步长;pid控制
  • ¥15 怎么让wx群机器人发送音乐
  • ¥15 fesafe材料库问题
  • ¥35 beats蓝牙耳机怎么查看日志
  • ¥15 Fluent齿轮搅油
  • ¥15 八爪鱼爬数据为什么自己停了
  • ¥15 交替优化波束形成和ris反射角使保密速率最大化
  • ¥15 树莓派与pix飞控通信
  • ¥15 自动转发微信群信息到另外一个微信群
  • ¥15 outlook无法配置成功