欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

用JSP编写通用信息发布程序

程序员文章站 2024-02-24 20:20:52
信息发布界面 提供发布信息的交互界面,调用 recordmessage.jsp程序。  saymessage.jsp  
信息发布界面

提供发布信息的交互界面,调用 recordmessage.jsp程序。  

saymessage.jsp  
<html> <head> <title> 信息发布</title>  
<meta content = "text/html; charset=gb2312" http-equiv = content-type>
<link href ="css_01.css" rel = stylesheet>
<meta content = "mshtml 5.00.3103.1000" name =generator> </head>
<body>
<% @ page contenttype=“ text/html; charset=gb2312”% >  

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

<jsp: usebean id ="rencommend" scope="page" class="ymbean.opdb"/>
<form action =recordmessage.jsp method =post name=sign>
<input name=dtkey type=hidden value=ta_routes>
<table bgcolor=#d5e8fd border=0 cellspacing=1 width="97%">
<tbody>
<tr> <td nowrap width="45%" height="185">
<div align=left>
<table bgcolor=#d5e8fd border=0 cellspacing=1 width="100%">
<tbody>
<tr> <td nowrap width="100%" >线路名称:
<input maxlength=100 name = routename size=36>
</td>
</tr>
<tr><td nowrap width="100%">显示序号:
<input maxlength=3 name=routeno size=36>
</td></tr>
<tr>
<td width="100%" >游览内容。文字超一行时 ,请您敲 enter键换行</td>
</tr>
<tr><td width="100%" height="162">
<textarea cols=55 name =c04 rows=9>
</textarea>
</td>
</tr></tbody></table></div></td></tr>
<tr><td align=middle colspan=2 nowrap>
<input name=cmdcommit type=submit value="提交">
</td></tr></tbody></table>
</form></center>
<div></div></body></html>  


连接数据库

通过调用 java bean连接 oracle数据库。  

opdb.java  

package ymbean; // java包  

import java.sql.* ;  

public class opdb {  

public opdb() { }  

public resultset executequery(string sql)  

{  

resultset rs = null;  

statement lstmt = null;  

try { lstmt = connectdb();  

rs = lstmt.executequery(sql);  

system.out.println(“ executequery:”+ sql);  

} catch(sqlexception ex) { return(null); }  

return rs;  

}  

public string executeupdate(string sql)  

{  

resultset rs = null;  

statement lstmt = null;  

try {  

lstmt = connectdb();  

lstmt.executeupdate(sql);  

system.out.println(“ executeupdate:”+ sql);  

lstmt.executeupdate(“ 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@192.168.0.1:1521:test” ;  

final string driver_string=“ oracle.jdbc.driver.  

oracledriver” ;  

connection lconn;  

try { class.forname(driverstr);  

lconn=drivermanager.getconnection(connectstr);  

lstmt=lconn.createstatement();  

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

return lstmt;  

}  

}//end opdb.java