如何从另一个页面的div获取会话值

时间:2012-07-09 06:50:03

标签: jquery ajax jsp session

我有3个jsp页面,即a.jsp,b.jsp和c.jsp,其中a.jsp我有一个div,其中b和c将加载,现在我的要求是我必须发送一个值表单b .jsp和c.jsp中的retrive,有什么想法吗?     检查我的代码

a.jsp

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<!--DVID=00014EAD-->
<html>
<head>

<title>Tabs in HTML with CSS</title>
<script src="resources/js2/jquery-1.6.2.min.js"></script>
<style type="text/css">
<!--
#tabs {
    border-bottom: .5em solid #0033CC;
    margin: 0;
    padding: 0;
}

#tabs li {
    display: inline;
    border-top: .1em solid #03c;
    border-left: .1em solid #03c;
    border-right: .1em solid #03c;
}

#tabs li a {
    text-decoration: none;
    padding: 0.25em 1em;
    color: #000;
}

#page1 #tabs li#tab1 a,#page2 #tabs li#tab2 a,#page3 #tabs li#tab3 a,.page4 li#tab4 a
    {
    padding: 0.25em 1em;
    background-color: #03c;
    color: #fff;
}
-->
</style>

<script type="text/javascript">

    function profile() {
        var xmlhttp;
        if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari
            xmlhttp = new XMLHttpRequest();
        } else {// code for IE6, IE5
            xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
        }
        xmlhttp.onreadystatechange = function() {
            if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
                document.getElementById("myDiv").innerHTML = xmlhttp.responseText;
            }
        }
        xmlhttp.open("GET", "b.jsp", true);
        xmlhttp.send();
    }

    function fields() {
        var xmlhttp;
        if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari
            xmlhttp = new XMLHttpRequest();
        } else {// code for IE6, IE5
            xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
        }
        xmlhttp.onreadystatechange = function() {
            if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
                document.getElementById("myDiv").innerHTML = xmlhttp.responseText;
            }
        }
        xmlhttp.open("GET", "c.jsp", true);
        xmlhttp.send();
    }
</script>
</head>

<body id="page3">
    <ul id="tabs">
        <li id="tab1"><a href="#" onclick="profile()">Tab 1</a></li>
        <li id="tab2"><a href="#">Tab 2</a></li>

    </ul>

    <div id="myDiv"></div>
</body>
</html>

b.jsp

<html>
        <head><title>getQueryString() method of request object.</title></head>
                <body>
                <form method="get">
                        <table border="0" cellspacing="0" cellpadding="0">
                                <tr>
                                        <td>User Name: </td>
                                        <td><input type="text" size="20" name="name" />
                                </tr>

                                <tr>
                                        <td> </td>
                                        <td><input type="button" id="NextBtn" value="Next" >
                                        </td>
                                </tr>
                        </table>
                       <%String name = request.getParameter("name");
                       session.setAttribute("name", name);
                     %>
                </form>

        </body>
</html>

c.jsp

<html>
<body>

<%

out.println("Name : " + (String)session.getAttribute("name") + "<br/>");

%>
</body>
</html>

1 个答案:

答案 0 :(得分:0)

我注意到两个错误:
在b.jsp中你必须纠正这个:

<form method="get" action="c.jsp">


在你的c.jsp中,你必须纠正这个:

<%= (String)session.getAttribute("name") %> <br>