0

我有这个代码:

    <script type="text/javascript">
    var endpoint = "http://localhost:8080/LWP/in.jsp?code=" + "<% out.println(request.getParameter("code")); %>";

    window.opener.location.href = endpoint;

    window.close();
    </script>

我期望它做的是将打开正在处理的浏览器窗口的页面重定向到

http://localhost:8080/LWP/in.jsp?code=<code here>

如果我删除脚本的 <% out.println() %> 部分,它可以正常工作,并且我会按预期重定向(减去传入的值)。

我对参数的输出做错了什么?

我也尝试删除 out.println。还是不行。

4

1 回答 1

0

弄清楚了。必须将值分配给一个新变量,然后使用它。

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<% String code = request.getParameter("code"); %>
<!DOCTYPE html>
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>JSP Page</title>
    <script type="text/javascript">
    var code = "<%=code%>";
    var endpoint = "http://localhost:8080/LWP/in.jsp?code=" + code;

window.opener.location.href = endpoint;

window.close();
    </script>
</head>
<body>

</body>
</html>
于 2013-05-01T19:50:52.220 回答