JavaScript怎么跳转到指定Action的某一方法中

网上查到是用window.location.href,但是不知道地址该怎么写,用的是Struts2,Action名叫LoginAction,所在包名是com.scujcc.actions,方法名叫logOut,方法里面写的是
public String logOut()
{
ActionContext.getContext().getSession().remove("customer");
return "success";
}
目的是要移除customer,不知道代码写对没有,还望高手指教一下

var url = "<%=path %>/namespace/login.action?参数=参数值";//通常先写一个变量来存地址
window.location.href(url);//这个是传到action的方式
要指定方法的话直接在struts的配置文件里面指定<action="Login" class="com.scujcc.actions.LoginAction" method="logOut">就行了
温馨提示:答案为网友推荐,仅供参考
第1个回答  推荐于2016-02-03
在jump.jsp下:
<script type="text/javascript">

window.location=" <%=request.getContextPath()%/namespace/actionname> ";
例如:window.location=" <%=request.getContextPath()%>/user/ResAction> ";
其中ResAction是配置文件中的Action名称。
</script>
通过以上就可实现了跳转到指定的Action。
第2个回答  2012-05-26
如public String logOut()方法在HelloReader中
另外这个要在struts.xml中配置,如
<!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN" " ">
<struts>
<package name="tutorial" extends="struts-default" >
<action name="helloReader" class="tutorial.HelloReader">
<result name="success">/HelloReader.jsp</result>
</action>
</package>
</struts>
第3个回答  2012-05-25
action!方法名.action

加叹号就行了追问

还是不行啊,是我的java代码写错了么?

追答

这就得问你自己的了。。。。是报错还是没有发送连接?

第4个回答  2012-05-25
你的action配置好后就可以指向actions类中的某个方法了,所以可以使用
window.localtion.href="action名字"

相关了解……

你可能感兴趣的内容

本站内容来自于网友发表,不代表本站立场,仅表示其个人看法,不对其真实性、正确性、有效性作任何的担保
相关事宜请发邮件给我们
© 非常风气网