JavaScript重定向 [英] Javascript redirect

查看:79
本文介绍了JavaScript重定向的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用javascript,这是我想做的事情: 1.发送一个类似于" http://localhost:8080/myapp/verify.htm?verifyId = Agkvhs "

I am working with javascript and here is what I am trying to do: 1. Send a get request which looks like "http://localhost:8080/myapp/verify.htm?verifyId=Agkvhs"

我的请求到达我的verify.jsp,其中我有javascript做一些特殊的事情,然后应使用verifyId重定向到另一个URL. 我的代码如下:

My requests reaches my verify.jsp in which I have javascript which does some special things and then should redirect to another url WITH the verifyId . My code looks like this:

function saveAndRedirect() {
    var verifyId = "<%=request.getParameter("verifyId")%>";
    var redirectUrl = "registrationVerify?verifyId=" + verifyId;
    window.alert("Got value " + redirectUrl);
    window.location = redirectUrl;

}

但是,这不起作用.我有一个警报,可以按预期向我显示带有附加参数的正确URL. 在我的web.xml文件中,我具有以下内容的servlet映射:

However this does not work. I have an alert which shows me the correct URL with the appended parameter as I expect. In my web.xml file I have a servlet mapping with the following:

 <servlet-mapping>
     <servlet-name>RegistrationVerificationServlet</servlet-name>
     <url-pattern>/registrationVerify*</url-pattern>
 </servlet-mapping>

在将verifyId附加到URL之前,此映射是可行的,我可以看到我的请求被撤销了,因为我附加了此参数,因此它无法正常工作.任何想法表示赞赏!

This mapping was workign before I appended the verifyId to the URL, I could see my request beign redicted to the servlet, since I appended this param it is not working. Any ideas much appreciated!

如果这不是理想的方法,请让我知道其他选择.

If this is not the ideal way to do this, please let me know any alternative.

谢谢

推荐答案

您的网址格式可疑.

使用其中一个

/registrationVerify

覆盖确切路径或

/registrationVerify/*

覆盖pathinfo的一部分.请注意,如果您愿意的话,您不需要显式地接受最后一个参数.

to cover the part of pathinfo. Note that you don't explicitly need the last one to be able to accept request parameters, if you'd thought that.

这篇关于JavaScript重定向的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆