Servlet中得到值,添加到reponse中,然后跳转到这个页面,用EL表达示或者jsp标签去取

解决方案 »

  1.   

    JSP写法:
    <a href="http://localhost:8080/stock/basicInfo.do?pager.offset=<span style="color: #FF0000;"><%=aaa %></span>">定位</a>
      

  2.   


    //输入stockId,显示stockName
    var xmlHttp;
    function showCustomer(str) {
    xmlHttp = GetXmlHttpObject();
    if (xmlHttp == null) {
    alert("浏览器不支持HTTP请求showCustomer方法!Browser does not support HTTP Request");
    return;
    }
    var url = "ajax.jsp";
    url = url + "?q=" + str;
    url = url + "&sid=" + Math.random();
    xmlHttp.onreadystatechange = stateChanged;
    xmlHttp.open("GET", url, true);
    xmlHttp.send(null);
    }
    function stateChanged() {
    if (xmlHttp.readyState == 4 || xmlHttp.readyState == "complete") {
    //将一个以“,”分割的数组重新分组
    var v = xmlHttp.responseText.split(",");
    //alert(v[1].replace(/\s+/g, ""));

    document.getElementById("stockNameId").value = v[1].replace(/\s+/g, "");
    document.getElementById("stockDataId").value = v[0].trim();
    }
    }function GetXmlHttpObject() {
    var objXMLHttp = null;
    if (window.XMLHttpRequest) {
    objXMLHttp = new XMLHttpRequest();
    } else if (window.ActiveXObject) {
    objXMLHttp = new ActiveXObject("Microsoft.XMLHTTP");
    }
    return objXMLHttp;
    }
      

  3.   


    <%@page contentType="text/html; charset=gb2312" import="java.sql.*"%><%
    String sql = (String) request.getParameter("q");
    //out.println(q);
    String str = "select * from t_stockdata where stockId='" + sql
    + "'";
    //String str1="select * from customers";
    // Class.forName("org.gjt.mm.mysql.Driver").newInstance();
    Class.forName("com.mysql.jdbc.Driver").newInstance();
    Connection con = java.sql.DriverManager.getConnection(
    "jdbc:mysql://localhost:3306/stock", "root", "root");
    Statement stmt = con.createStatement();
    ResultSet rst = stmt.executeQuery(str); while (rst.next()) {
    %><%=rst.getString("id")%>
    <%=","%>
    <%=rst.getString("stockName")%>
    <%
    }
    //关闭连接、释放资源
    rst.close();
    stmt.close();
    con.close();
    %>
      

  4.   


    <script src="script/selectcustomer.js" type="text/javascript"></script>
               <form action="basicInfo.do" method="post">
               <input type="hidden" name="method" value="find">
                <tr>
                   <td>
                  股票代码:<input type=text name="stockId" id="stockIdId" value="" size="10" maxlength="10" onblur="showCustomer(this.value)" >             
    股票名称:<input type=text name="stockName" id="stockNameId" value="" size="10" maxlength="10">
    <input type="submit" value="查询"/>
    </td>

    <td>
    <!-- 定位股票方法,目前无法完成连接中的赋值 -->
    股票Id:<input type=text name="stockData" id="stockDataId" value="" size="10" maxlength="10">
    <a href="http://localhost:8080/stock/basicInfo.do?pager.offset=aaa">定位</a>
    </td>
    </tr>
    </script> 
    相关代码就是这样的,股票id值确定拿出来了,但是目前不还知道怎么把这个值赋给aaa
      

  5.   

    <%String stockId=rst.getString("id")%><a href="http://localhost:8080/stock/basicInfo.do?pager.offset=<%=stockId%>">定位</a>
      

  6.   

    <%@page contentType="text/html; charset=gb2312" import="java.sql.*"%><%
            String stockId = "-1";
    String sql = (String) request.getParameter("q");
    //out.println(q);
    String str = "select * from t_stockdata where stockId='" + sql
    + "'";
    //String str1="select * from customers";
    // Class.forName("org.gjt.mm.mysql.Driver").newInstance();
    Class.forName("com.mysql.jdbc.Driver").newInstance();
    Connection con = java.sql.DriverManager.getConnection(
    "jdbc:mysql://localhost:3306/stock", "root", "root");
    Statement stmt = con.createStatement();
    ResultSet rst = stmt.executeQuery(str); while (rst.next()) {
            stockId = rst.getString("id");
    %><%=rst.getString("id")%>
    <%=","%>
    <%=rst.getString("stockName")%>
    <%
    }
    //关闭连接、释放资源
    rst.close();
    stmt.close();
    con.close();
    %><script src="script/selectcustomer.js" type="text/javascript"></script>
               <form action="basicInfo.do" method="post">
               <input type="hidden" name="method" value="find">
                <tr>
                   <td>
                  股票代码:<input type=text name="stockId" id="stockIdId" value="" size="10" maxlength="10" onblur="showCustomer(this.value)" >             
    股票名称:<input type=text name="stockName" id="stockNameId" value="" size="10" maxlength="10">
    <input type="submit" value="查询"/>
    </td>

    <td>
    <!-- 定位股票方法,目前无法完成连接中的赋值 -->
    股票Id:<input type=text name="stockData" id="stockDataId" value="" size="10" maxlength="10">
    <a href="http://localhost:8080/stock/basicInfo.do?pager.offset=<%=stockId %>">定位</a>
    </td>
    </tr>
    </script> 
      

  7.   

    <%@page contentType="text/html; charset=gb2312" import="java.sql.*"%><%
            String stockId = "-1";
    String sql = (String) request.getParameter("q");
    //out.println(q);
    String str = "select * from t_stockdata where stockId='" + sql
    + "'";
    //String str1="select * from customers";
    // Class.forName("org.gjt.mm.mysql.Driver").newInstance();
    Class.forName("com.mysql.jdbc.Driver").newInstance();
    Connection con = java.sql.DriverManager.getConnection(
    "jdbc:mysql://localhost:3306/stock", "root", "root");
    Statement stmt = con.createStatement();
    ResultSet rst = stmt.executeQuery(str); while (rst.next()) {
            stockId = rst.getString("id");
    %><%=rst.getString("id")%>
    <%=","%>
    <%=rst.getString("stockName")%>
    <%
    }
    //关闭连接、释放资源
    rst.close();
    stmt.close();
    con.close();
    %><script src="script/selectcustomer.js" type="text/javascript"></script>
               <form action="basicInfo.do" method="post">
               <input type="hidden" name="method" value="find">
                <tr>
                   <td>
                  股票代码:<input type=text name="stockId" id="stockIdId" value="" size="10" maxlength="10" onblur="showCustomer(this.value)" >             
    股票名称:<input type=text name="stockName" id="stockNameId" value="" size="10" maxlength="10">
    <input type="submit" value="查询"/>
    </td>

    <td>
    <!-- 定位股票方法,目前无法完成连接中的赋值 -->
    股票Id:<input type=text name="stockData" id="stockDataId" value="" size="10" maxlength="10">
    <a href="http://localhost:8080/stock/basicInfo.do?pager.offset=<%=stockId %>">定位</a>
    </td>
    </tr>
    </script> 
    必须把两段代码合在一起吗?我这三段代码在三个文件中啊
      

  8.   

    <%@page contentType="text/html; charset=gb2312" import="java.sql.*"%><%
            String stockId = "-1";
    String sql = (String) request.getParameter("q");
    //out.println(q);
    String str = "select * from t_stockdata where stockId='" + sql
    + "'";
    //String str1="select * from customers";
    // Class.forName("org.gjt.mm.mysql.Driver").newInstance();
    Class.forName("com.mysql.jdbc.Driver").newInstance();
    Connection con = java.sql.DriverManager.getConnection(
    "jdbc:mysql://localhost:3306/stock", "root", "root");
    Statement stmt = con.createStatement();
    ResultSet rst = stmt.executeQuery(str); while (rst.next()) {
            stockId = rst.getString("id");
    %><%=rst.getString("id")%>
    <%=","%>
    <%=rst.getString("stockName")%>
    <%
    }
    //关闭连接、释放资源
    rst.close();
    stmt.close();
    con.close();
    %><script src="script/selectcustomer.js" type="text/javascript"></script>
               <form action="basicInfo.do" method="post">
               <input type="hidden" name="method" value="find">
                <tr>
                   <td>
                  股票代码:<input type=text name="stockId" id="stockIdId" value="" size="10" maxlength="10" onblur="showCustomer(this.value)" >             
    股票名称:<input type=text name="stockName" id="stockNameId" value="" size="10" maxlength="10">
    <input type="submit" value="查询"/>
    </td>

    <td>
    <!-- 定位股票方法,目前无法完成连接中的赋值 -->
    股票Id:<input type=text name="stockData" id="stockDataId" value="" size="10" maxlength="10">
    <a href="http://localhost:8080/stock/basicInfo.do?pager.offset=<%=stockId %>">定位</a>
    </td>
    </tr>
    </script> 
    必须把两段代码合在一起吗?我这三段代码在三个文件中啊
    为什么是3个文件? <a href="http://localhost:8080/stock/basicInfo.do?pager.offset=<%=stockId %>">定位</a>  这个页面是从哪里进入的?
      

  9.   


    <%@page contentType="text/html; charset=gb2312" import="java.sql.*"%><%
    String stockId = "-1";
    String sql = (String) request.getParameter("q");
    //out.println(q);
    String str = "select * from t_stockdata where stockId='" + sql
    + "'";
    //String str1="select * from customers";
    // Class.forName("org.gjt.mm.mysql.Driver").newInstance();
    Class.forName("com.mysql.jdbc.Driver").newInstance();
    Connection con = java.sql.DriverManager.getConnection(
    "jdbc:mysql://localhost:3306/stock", "root", "root");
    Statement stmt = con.createStatement();
    ResultSet rst = stmt.executeQuery(str); while (rst.next()) {
    stockId = rst.getString("id");
    %><%=rst.getString("id")%>
    <%=","%>
    <%=rst.getString("stockName")%>
    <%
    }
    //关闭连接、释放资源
    rst.close();
    stmt.close();
    con.close();
    %>上面是一个公用的文件ajax.jsp
    //输入stockId,显示stockName
    var xmlHttp;
    function showCustomer(str) {
    xmlHttp = GetXmlHttpObject();
    if (xmlHttp == null) {
    alert("浏览器不支持HTTP请求showCustomer方法!Browser does not support HTTP Request");
    return;
    }
    var url = "ajax.jsp";
    url = url + "?q=" + str;
    url = url + "&sid=" + Math.random();
    xmlHttp.onreadystatechange = stateChanged;
    xmlHttp.open("GET", url, true);
    xmlHttp.send(null);
    }
    function stateChanged() {
    if (xmlHttp.readyState == 4 || xmlHttp.readyState == "complete") {
    //将一个以“,”分割的数组重新分组
    var v = xmlHttp.responseText.split(",");
    //alert(v[1].replace(/\s+/g, ""));

    document.getElementById("stockNameId").value = v[1].replace(/\s+/g, "");
    document.getElementById("stockDataId").value = v[0].trim();
    }
    }function GetXmlHttpObject() {
    var objXMLHttp = null;
    if (window.XMLHttpRequest) {
    objXMLHttp = new XMLHttpRequest();
    } else if (window.ActiveXObject) {
    objXMLHttp = new ActiveXObject("Microsoft.XMLHTTP");
    }
    return objXMLHttp;
    }这个是一个selectcustomer.js
    <script src="script/selectcustomer.js" type="text/javascript"></script>
               <form action="basicInfo.do" method="post">
                   <input type="hidden" name="method" value="find">
                    <tr>
                       <td>
                         股票代码:<input type=text name="stockId" id="stockIdId" value="" size="10" maxlength="10" onblur="showCustomer(this.value)" >                
                        股票名称:<input type=text name="stockName" id="stockNameId" value="" size="10" maxlength="10">                                                               
                        <input type="submit" value="查询"/>
                        </td>
                         
                        <td>
                        <!-- 定位股票方法,目前无法完成连接中的赋值 -->
                            股票Id:<input type=text name="stockData" id="stockDataId" value="" size="10" maxlength="10">
                            <a href="http://localhost:8080/stock/basicInfo.do?pager.offset=<%=stockId %>">定位</a>
                        </td>
                    </tr>
    </script> 这个是我从index.jsp页面中复制出来,每一个页面都有这段代码onblur="showCustomer(this.value)" 调用selectcustomer.js中的showCustomer(this.value)
    然后selectcustomer.js中的
    document.getElementById("stockNameId").value = v[1].replace(/\s+/g, "");
    document.getElementById("stockDataId").value = v[0].trim();
    但是其实我的目的事项把v[0]的值赋给aaa的
      

  10.   

    学了下jquery ,感觉也达不到我想要的啊