当前位置:编程学习 > JSP >>

帮我修改下这段jsp的代码吧 T.T

<%@ page language="java" pageEncoding="ISO-8859-1"%> <%@ page import="java.sql.*"%> <html lang="true"> <head> <title>zheng.jsp</title> </head> <body> <% Connection con=null; Statement st=null; ResultSet rs= null; Class.forName("oracle.jdbc.driver.OracleDriver"); try { con = DriverManager.getConnection("jdbc:oracle:thin:@10.192.39.8:1521:"SITDB2","bbb","cccc"); st = con.createStatement(); rs = st.executeQuery("select * from BBB_bILL"); } catch (SQLException e) { e.printStackTrace(); } finally{ if(st!=null) st.close(); if(con!=null) con.close(); } %> </body> </html> 要求在页面添加一个能显示sql数据的窗口 然后一个按钮 在点击按钮的时候 把上面查询出来的东西显示到窗口。。。。
答案:<html>
  <head>
    <title>zheng.jsp</title>
  </head>
  <body>   
  <form action="<%=request.getContextPath() %>/***Action.action" method="post">
    <table>
     <tr>
      <td><input type="text" name="sqlStr"/></td>
     </tr>
     <tr>
      <td><input type="submit" value="提交" /></td>
     </tr>
    </table>
  </form>
</body>
</html>

后台:
String sql = request.getParameter("sqlStr");
if(sql!=null && sql.trim().length()>0){
 rs  =  st.executeQuery(sql);
}else{
 rs  =  st.executeQuery("select * from BBB_bILL");
}
其他:if(user!=null)
可能是这里错了,这里应该改成这样吧if(user.equals("")) if(user!=null)
可能是这里错了,这里应该改成这样吧if(user.equals("")) 

上一个:我在server.xml里写了虚拟目录的代码后,tomcat就运行不了,删了就能正常运行,我正在学习JSP和PHP,高手
下一个:在JSP中,只有一行代码:${1+2},运行将输出( )。

CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,