日期:2014-05-17  浏览次数:20580 次

菜鸟求助!!JSP页面间传值问题
我有两个JSP的页面,分别为1.jsp和2.jsp。
其中1.jsp中有语句

  <body>
  <img src="thumbs/9.jpg" width="179" height="100" alt="" onclick="show_id2('9')"/>
  <script type="text/javascript" src="1.js"></script> 
  </body>


1.js内容如下:

var tu1;
tu1 = 3;

function show_id2(str){
  tu1 = str;
}


2.jsp

  <body>

Connection conn=null;
        PreparedStatement pstmt = null;
     try {
Class.forName("com.mysql.jdbc.Driver");//加载JDBC驱动程序 
conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/bbs","root","root");//连接MySQL数据库
}catch (ClassNotFoundException e) {
out.println("找不到驱动类");
} catch (SQLException e) {
out.println("连接MySQL数据库失败");
}
try{
Statement stmt = conn.createStatement(); 
            String queryAll = "insert into user(id,username,password,email,sex) values(null,'candy','123','666','nan');";
int rs = stmt.executeUpdate(queryAll);
//获得所有记录

if(rs != 0)
        {
             out.println(tu1);
         }
          else
         {
               response.sendRedirect("No.jsp");
         }
  }catch (SQLException e) {
out.println("查询用户信息失败");
e.printStackTrace();
}
     %>
  </body>


我想在2.jsp中out.println(tu1);处用到tu1的值,怎么办?

------解决方案--------------------
在1.jsp js代码中加入