how to pass the string array from A jsp to B jsp

Discussion in 'Java' started by =?big5?B?TWluZ6dC?=, Jun 24, 2006.

  1. Hi!

    Do anyone know pass the string array from A jsp to B jsp? For
    example, I want to pass Strresult to query.jsp for operation. How can
    I do? THX!

    Ming

    <%@page contentType="text/html"%>
    <%@page pageEncoding="Big5"%>
    <%@page import = "java.sql.*"%>
    <html>
    <head><title>¥D¾÷ªO¬d¸ßµ²ªG</title></head>
    <body>
    <form action="query.jsp" method="post">
    <%
    String Strresult[] = new String[10];
    String Test = "";
    int i = 0;
    Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
    Connection con =
    DriverManager.getConnection("jdbc:eek:dbc:MT450");
    Statement smt = con.createStatement();
    String name =
    new
    String(request.getParameter("name").getBytes("ISO-8859-1"));
    String sql = "select Standard from Combinations where Model ='"
    + name + "'";
    String color;
    ResultSet rs = smt.executeQuery(sql);

    while(rs.next()){
    Strresult=rs.getString(1);
    out.println(Strresult[i++]+"<p>");

    }
    con.close();
    %>
    <input type="submit" value="½T»{¥æ©ö">
    <input type='hidden' name='name' value='<%= name %>'>
    <input type='hidden' name='Test' value='<%= Test %>'>

    </form>

    </body>
    </html>
     
    =?big5?B?TWluZ6dC?=, Jun 24, 2006
    #1
    1. Advertising

  2. Ming伯 wrote:
    > Hi!
    >
    > Do anyone know pass the string array from A jsp to B jsp? For
    > example, I want to pass Strresult to query.jsp for operation. How can
    > I do? THX!


    Most obvious method is using session. In your example it does not
    look like you are submitting anything important, or any user
    input, so, it does not seem that first jsp should submit
    data to second. If that is the true, then you can use the
    request object and, add attribute to it (request.setAttribute()), and
    let the first jsp to forward (jsp:forward) request to second (chaining).

    DG
     
    =?UTF-8?B?RHJhxb5lbiBHZW1pxIc=?=, Jun 24, 2006
    #2
    1. Advertising

  3. Ming§B wrote:
    > Hi!
    >
    > Do anyone know pass the string array from A jsp to B jsp? For
    > example, I want to pass Strresult to query.jsp for operation. How can
    > I do? THX!



    What keeps you from sending it the same way that you send "name" or "Test"?

    --
    John O'Conner
     
    John O'Conner, Jun 24, 2006
    #3
  4. Ming伯 schrieb:

    > String name =
    > new
    > String(request.getParameter("name").getBytes("ISO-8859-1"));
    > String sql = "select Standard from Combinations where Model ='"
    > + name + "'";


    I would suggest reading one or two articles about "SQL-Injection-attacks"
    and how to prevent them (hint: PreparedStatement).

    Jan
     
    Jan Peter Stotz, Jun 24, 2006
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    0
    Views:
    4,507
  2. sridhar kumar ch
    Replies:
    1
    Views:
    8,756
  3. sridhar kumar ch
    Replies:
    0
    Views:
    827
    sridhar kumar ch
    Jun 28, 2006
  4. jelle
    Replies:
    4
    Views:
    423
    jelle
    Apr 26, 2005
  5. Replies:
    3
    Views:
    346
    Martin Honnen
    Jun 15, 2006
Loading...

Share This Page