-1

我有 3 个 jsp 页面,即 a.jsp、b.jsp 和 c.jsp,在 a.jsp 中我有一个 div 将加载 b 和 c,现在我的要求是我必须发送一个值表单 b.jsp 和在 c.jsp 中检索,知道吗?检查我的代码

一个.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>
4

1 回答 1

0

我注意到有两个错误:
在 b.jsp 中,您必须更正这一点:

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


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

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


于 2012-07-09T07:48:47.630 回答