熱點推薦:
您现在的位置: 電腦知識網 >> 編程 >> Java編程 >> JSP教程 >> 正文

用JSP編寫通用信息發布程序

2013-11-15 11:53:04  來源: JSP教程 

  信息發布界面

  提供發布信息的交互界面調用 recordMessagejsp程序

  sayMessagejsp
<HTML> <HEAD> <TITLE> 信息發布</TITLE>
<META content = "text/html; charset=GB" httpequiv = ContentType>
<LINK href ="css_css" rel = stylesheet>
<META content = "MSHTML " name =GENERATOR> </HEAD>
<BODY>
<% @ page contentType=“ text/html; charset=GB”% >

  <% @ page language=“ java” import=“ java sql *”% >

  <jsp: usebean id ="rencommend" scope="page" class="ymbeanopDb"/>
<form action =recordmessagejsp method =post name=sign>
<input name=dtkey type=hidden value=ta_routes>
<table bgcolor=#defd border= cellspacing= width="%">
<tbody>
<tr> <td nowrap width="%" height="">
<div align=left>
<table bgcolor=#defd border= cellspacing= width="%">
<tbody>
<tr> <td nowrap width="%" >線路名稱
<input maxlength= name = routename size=>
</td>
</tr>
<tr><td nowrap width="%">顯示序號
<input maxlength= name=routeno size=>
</td></tr>
<tr>
<td width="%" >游覽內容文字超一行時 請您敲 Enter鍵換行</td>
</tr>
<tr><td width="%" height="">
<TEXTAREA cols= name =c rows=>
</TEXTAREA>
</TD>
</TR></TBODY></TABLE></DIV></TD></TR>
<TR><TD align=middle colspan= nowrap>
<input name=cmdcommit type=submit value="提交">
</td></tr></tbody></table>
</form></center>
<div></div></body></html>
 

  連接數據庫

  通過調用 Java Bean連接 Oracle數據庫

  opDbjava

  package ymbean; // java包

  import javasql* ;

  public class opDb {

  public opDb() { }

  public ResultSet executeQuery(String sql)

  {

  ResultSet rs = null;

  Statement lstmt = null;

  try { lstmt = connectdb();

  rs = lstmtexecuteQuery(sql);

  Systemoutprintln(“ executeQuery:”+ sql);

  } catch(SQLException ex) { return(null) }

  return rs;

  }

  public String executeUpdate(String sql)

  {

  ResultSet rs = null;

  Statement lstmt = null;

  try {

  lstmt = connectdb();

  lstmtexecuteUpdate(sql);

  Systemoutprintln(“ executeUpdate:”+ sql);

  lstmtexecuteUpdate(“ commit” );

  }catch(SQLException ex) {}

  return(“ executeUpdate ok” );

  }

  //連接數據庫

  public Statement connectdb()

  { Statement lstmt=null;

  Connection conn=null;

  final String connect_string=“ jdbc:oracle:thin:scott/tiger@::test” ;

  final String driver_string=“ oraclejdbcdriver

  OracleDriver” ;

  Connection lconn;

  try { ClassforName(driverstr);

  lconn=DriverManagergetConnection(connectstr);

  lstmt=lconncreateStatement();

  } catch (Exception e) { return(null);}

  return lstmt;

  }

  }//end opDbjava


From:http://tw.wingwit.com/Article/program/Java/JSP/201311/19810.html
    推薦文章
    Copyright © 2005-2013 電腦知識網 Computer Knowledge   All rights reserved.