当前位置: 首页 > 图文教程 > 网络编程 > JSP > 用JSP编写通用信息发布程序

JSP
客户端界面中可视化的实现树形框架的设计
Win2000下JBoss开发环境配置
调试处理系统核心文件
Matrix java 大讲坛 之 可用性与人机界面
JMX调试----第三方工具使访问更加容易
用BSF如何在Java中嵌入javascript以及如何在javascript中
再次提醒\" 请不要做浮躁的人\"
从Coding Fan到真正的技术专家(cjsdn)
数据库BEAN:RESIN连接池
基于Java的Web服务器工作原理(一)
XDE中模式驱动的设计与开发(三)
页面流(Page flow)表单验证
高级页面流(Page flow):嵌套、异常处理和 Global.app
请不要做浮躁的人(ZT-必读)
解决日期选择问题,一劳永逸(使用Decorator模式实现日期选择组件)(二)
解决日期选择问题,一劳永逸(使用Decorator模式实现日期选择组件)(三)
解决日期选择问题,一劳永逸(使用Decorator模式实现日期选择组件)(四)
解决日期选择问题,一劳永逸(使用Decorator模式实现日期选择组件)(五)
EJB技术之旅(一)
MVC渐行渐进(二)

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


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-09-13   浏览: 46 ::
收藏到网摘: n/a

信息发布界面
提供发布信息的交互界面,调用 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/[email protected]: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