当前位置: 代码迷 >> Java Web开发 >> 在页面A使用servlet接收值,在页面B中使用,该如何解决
  详细解决方案

在页面A使用servlet接收值,在页面B中使用,该如何解决

热度:27   发布时间:2016-04-17 01:11:30.0
在页面A使用servlet接收值,在页面B中使用
页面A代码

  <form id="form1" name="form1" method="post" action="/TestOracleFenye/servlet/TabelName">
  <input type="text" id="tableName" name="tableName"/>
  <input type="submit" name="button2" id="button2" value="确定"/>
  </form>

页面B代码:
String tableName_s=(String)request.getAttribute("t_name");

servlet代码: String t_name=request.getParameter("tableName");
System.out.println(t_name);
request.setAttribute("t_name", t_name);
request.getRequestDispatcher("/ProicedureTest.jsp").forward(request, response);


我想把页面A,INPUT中的值,在页面B上使用,用来查询表,变量t_name好像是被销毁了,当点击查询第二页这个变量就不能使用了。无效SQL


java.sql.SQLException: ORA-00903: 表名无效


------解决方案--------------------
你应该用转发response.sendRedirect(),而不是重定向request.getRequestDispatcher("/ProicedureTest.jsp").forward(request, response);

------解决方案--------------------
这样这是我的购物车实现代码
request.getSession().setAttribute("cart", cart);

request.getSession().getAttribute("cart");
  相关解决方案