on单击到另一个 JSP 不起作用



我在另一个JSP的onclick函数上遇到了问题。
我想检查会话属性是否与我的显示中的 JohnMark 相同.jsp,那么它将以该名称显示在新的.jsp上。
我有一个登录名.jsp并成功地在显示器上工作.jsp它能够通过使用 ValidationServlet 中的会话显示名称。
display.jsp中实现代码后,我不断得到请求的资源()不可用。
已经在那里呆了 3 天,现在有点迷路了。
希望你们能帮我解决这个问题,提前谢谢。

这是我的显示器.jsp代码

<!DOCTYPE html> 
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>Application</title>
    </head>
    <body>
        <h1>Display</h1>
        Welcome <b><%=session.getAttribute("name")%></b>,
        <table border="0">
            <tr>
                <th colspan="3"></th>
            </tr>
            <tr>
                <td>
                    <form action="loan" method="post">
                        <input type="submit" value="New" onClick="new()"/>
                    </form>
                    <SCRIPT LANGUAGE="JavaScript">
                        function new(){          
                            if (session.getAttribute("name") === "John") {
                                session.setAttribute("name", "John");
                                document.new.action="new.jsp";
                            }
                            if (session.getAttribute("name") === "Mark") {
                                session.setAttribute("name", "Mark");
                                document.new.action="new.jsp";
                            } else {
                                session.setAttribute("name", null);
                                document.new.action="new.jsp";
                            }
                            new.submit();
                        }
                    </SCRIPT>
                </td>
                <td colspan="2"></td>
            </tr>
        </table>
    </body>
</html>

这是我的新代码.jsp

<!DOCTYPE html> 
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>Application</title>
    </head>
    <body>
        <h1>New</h1>
        Hello <b><%=session.getAttribute("name")%></b>
    </body>
</html>

你会得到像beelow这样的会话变量:

var firstName='<%= session.getAttribute("name")%>';

我认为你不能从java脚本访问会话变量,因为它在客户端执行,这段代码的输出是什么session.getAttribute("name"),你得到期望值了吗?

或者,您可以允许此链接访问 js 中的会话变量

最新更新