首先说明下,是在action里面,非jsp中,jsp里,可用如下方法实现:
function openResult()
{
var url = "result.jsp";
window.showModalDialog(url, window, "dialogWidth=250px;dialogHeight=350px");//模态对话框
}我的struts.xml主要代码如下:
<action name="userAdd" class="com.test.action.UserAction" method="add">
<result name="result">/result.jsp</result>
</action>
UserAction中add方法中主要代码如下://处理过程(略)
return "result";//处理完成,转向/result.jsp,这样当然就请求转发到result.jsp去了,我要实现转向result.jsp时成为模式窗口怎么实现呢?以下是我的方法,但有问题:
PrintWriter out = response.getWriter();
out.print("<script>window.showModalDialog(‘result.jsp’, window, 'dialogWidth=250px;dialogHeight=350px');</script>");
return null;//使用这句弹出模式窗口的同时,之前的窗口变成空白页了,我不希望变成空白页要保留之前的窗口。但若不使用return编译要通不过,很麻烦。可能表述得不大好,不知道各位大侠有没明白我的意思啊,总之,就是,如何改acton中的方法或struts.xml中的配置,使return 到jsp时,成为模式窗口。当然模式窗口我是实现了,可是,会转向一个空白页,这个如何解决呢?我这样做法有没问题呢?(注:在jsp中转向action来实现先不讨论)
function openResult()
{
var url = "result.jsp";
window.showModalDialog(url, window, "dialogWidth=250px;dialogHeight=350px");//模态对话框
}我的struts.xml主要代码如下:
<action name="userAdd" class="com.test.action.UserAction" method="add">
<result name="result">/result.jsp</result>
</action>
UserAction中add方法中主要代码如下://处理过程(略)
return "result";//处理完成,转向/result.jsp,这样当然就请求转发到result.jsp去了,我要实现转向result.jsp时成为模式窗口怎么实现呢?以下是我的方法,但有问题:
PrintWriter out = response.getWriter();
out.print("<script>window.showModalDialog(‘result.jsp’, window, 'dialogWidth=250px;dialogHeight=350px');</script>");
return null;//使用这句弹出模式窗口的同时,之前的窗口变成空白页了,我不希望变成空白页要保留之前的窗口。但若不使用return编译要通不过,很麻烦。可能表述得不大好,不知道各位大侠有没明白我的意思啊,总之,就是,如何改acton中的方法或struts.xml中的配置,使return 到jsp时,成为模式窗口。当然模式窗口我是实现了,可是,会转向一个空白页,这个如何解决呢?我这样做法有没问题呢?(注:在jsp中转向action来实现先不讨论)
{
var url = "userAdd!add.do";
window.showModalDialog(url, window, "dialogWidth=250px;dialogHeight=350px");//模态对话框
}
"之前的窗口变成空白页了"这个是因为你的请求得到了回应,所以页面被刷新了。这就是变成空白的原因,如果想不改变之前页面,要发送异步请求(建议采用ajax请求实现)。
最后建议lz根据自己的业务还是用js函数来实现比较好。
这个是在jsp中,转向action实现的,我说了,这种方法先不讨论,我想直接在action中实现,怎么办?
(注:之所以我想在action方法中实现,一个原因是,我使用:<s:submit value="提交">提交<form>转向action时,没办法实现这种模式窗口的效果)
似乎<s:submit>作废了,要一个个取到参数,再通过ajax传到action去,相关代码如下:
createHttpRequest();
var url = "userAdd.action?parm1=" + document.all.v1.value + "&parm2=" + document.all.v2.value + "&";
xmlHttp.open("post", url, true);
xmlHttp.setRequestHeader("Content-Type", "text/html;charset=gbk");
xmlHttp.onreadystatechange = HandMethod;
xmlHttp.send(null);
上面我只传两个参数parm1与parm2,实际上,我参数有几十个,这样做显然不爽。就算是可以传对象或数组参数,但首先总得把参数值取出来再组成对像或数组再传啊,一样的麻烦,各位有何想法呢?(注:ajax我就知道这样用,可能其它高级用法不会这么麻烦的传这么多参数,请指教)
并且改页面页面加载那个世界
保留.异步用ajax解决,但字段多了也不方便.也许只能将就的用了....
out.print("<script language='javascript' type='text/javascript'>alert('请先登陆');window.navigate('*.jsp');</script>");//'*'号表示你想跳转的页面
下面是我在实际项目中的代码:
1.拦截器代码片段:
public String intercept(ActionInvocation actionInvocation) throws Exception {
ActionContext context = ActionContext.getContext();
HttpServletResponse response = ServletActionContext.getResponse();
response.setContentType("text/html;charset=GBK");
PrintWriter out = response.getWriter();
Map<String,Employe> session = context.getSession();
if(session.get("employe")==null){
out.print("<script language='javascript' type='text/javascript'>alert('请先登陆');window.navigate('login.jsp');</script>");
return null;
}
else
return actionInvocation.invoke();
}struts.xml代码片段:
<action name="test_buy" class="com.control.emplomanager.Test_buy">
<result name="success" type="redirect">buyticket.jsp</result>
<result name="login" type="redirect">login.jsp</result>
<interceptor-ref name="defaultStack"></interceptor-ref>
<interceptor-ref name="loginCheck"></interceptor-ref>
</action>