RedHatLinux网络服务器构架实务(八)

王朝system·作者佚名  2008-05-19
宽屏版  字体: |||超大  

//获取字段值,参数为字符串--字段名

public String getString( String fieldName )

throws SQLException {

return rs.getString(fieldName) ;

}

//上移指针

public boolean previous()

throws SQLException {

if( rs==null )

throw new SQLException( "ResultSet is null." ) ;

return rs.previous() ;

}

//下移指针

public boolean next()

throws SQLException {

if( rs==null )

throw new SQLException( "ResultSet is null." ) ;

return rs.next() ;

}

//指针最上

public boolean first()

throws SQLException {

if( rs==null )

throw new SQLException( "ResultSet is null." ) ;

return rs.first() ;

}

//指针最下

public boolean last()

throws SQLException {

if( rs==null )

throw new SQLException( "ResultSet is null." ) ;

return rs.last() ;

}

//清除变量,当你仅需要清除变量而不关库时可调用此方法

private void clear () throws SQLException {

if( rs!=null ) rs.close() ;

rs=null ;

if( stmt!=null ) stmt.close() ;

stmt=null ;

}

//清除变量并关库

public void close() throws SQLException {

clear () ;

if( conn==null )

throw new SQLException( "This connection has been closed already." ) ;

if( conn.isClosed() )

throw new SQLException( "This connection has been closed." ) ;

conn.close() ;

conn=null ;

}

}

2 编写逻辑层代码

##在客户端创建dbbridge.jsp,然后上传到服务器端即可:

##上级要来视察某官僚的工作,只见该官僚指挥若定:

##逻辑层对处理层说:小子,去跟我的后台联络一下。

//连库并初始化

<jsp:useBean id="bridge" class="com.gledecity.yesgo.sql.DBBridge" />

##逻辑层对处理层说:把我们今年的工作成果准备一下。

//执行SQL语句

<%bridge.execSQL("select * from prov");

##逻辑层对处理层说:材料准备好了?干得好!上级一来看到一片数据。//循环显示

while(bridge.next())

{

out.print(bridge.getString("prov_id")+bridge.getString("prov_name")+"<br>");}

##逻辑层对处理层说:好了好了,政绩显示完毕,你们通通滚蛋吧。 //关闭所有变量

bridge.close();%>

##上级看后非常满意,拍拍官僚的肩膀:"干得不错!"官僚一高兴,说:"哪里哪里,都是下属办事得力!"

3 测试该程序

lynx http://www.yesgo.loc/dbbridge.jsp

##当然你也可以在客户端浏览器测试,只是你需要将你服务器的IP添加到你网络设置中的DNS列表中。

##处理的结果是数据库中所有的数据:

1安徽

2北京

3重庆

4福建

5甘肃

6广东

7广西

8贵州

9海南

10河北

11黑龙江

12河南

13湖北

14湖南

15内蒙古

16江苏

17江西

18吉林

19辽宁

20宁夏

21青海

22山西

23陕西

24山东

25上海

26四川

27天津

28西藏

29新疆

30云南

31浙江

32香港

33澳门

34台湾

例四:测试PHP

1 创建源文件

touch /home/www/test.php

chmod 701 /home/www/test.php

2 编辑源文件

vi test.php

## 源代码如下:

<?

phpinfo();

?>

3 测试该程序

lynx http://www.yesgo.loc/test.php

//结果是大家熟知的服务器端变量列表。

Step 17 Configuration debug

##调试过程可能的错误如下:

常见错误一:You don't have permission

Forbidden

You don't have permission to access / on this server.

Apache/1.3.22 Server at www.yesgo.loc Port 80

原因可能是:

1、你没有为该目录或者该文件设置guest组权限;

2、你没有将该文件名设置为默认页面,尤其是在仅用域名访问的情况下。

解决办法:

chmod 701 /home/www

chmod 701 /home/www/*

vi /usr/local/apache/conf/httpd.conf

DirectoryIndex index.html index.jsp index.xtp index.php index.php3

常见错误二:404 Not Found

404 Not Found

/index.jsp was not found on this server.

Resin 2.0.5 (built Thu Nov 15 17:56:24 PST 2001)

原因可能是:

1、你请求的文件名输入错误;

2、你没有在resin.conf和httpd.conf中都建立相应的主机。

解决办法:

1、检查文件名,尤其注意大小写问题;

2、参照Resin install步骤中的配置支持JSP的虚拟主机部分。

常见错误三:java.lang.ClassNotFoundException

500 Servlet Exception

java.lang.ClassNotFoundException: org.gjt.mm.mysql.Driver

at com.caucho.util.DynamicClassLoader.loadClass(DynamicClassLoader.java:479)

at java.lang.ClassLoader.loadClass(ClassLoader.java:253)

at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:313)

at java.lang.Class.forName0(Native Method)

at java.lang.Class.forName(Class.java:120)

at _cnmysql__jsp._jspService(/cnmysql.jsp:4)

at com.caucho.jsp.JavaPage.service(JavaPage.java:74)

at com.caucho.jsp.Page.subservice(Page.java:485)

at com.caucho.server.http.FilterChainPage.doFilter(FilterChainPage.java:176)

at com.caucho.server.http.Invocation.service(Invocation.java:278)

at com.caucho.server.http.CacheInvocation.service(CacheInvocation.java:129)

at com.caucho.server.http.RunnerRequest.handleRequest(RunnerRequest.java:338)

at com.caucho.server.http.RunnerRequest.handleConnection(RunnerRequest.java:270)

at com.caucho.server.TcpConnection.run(TcpConnection.java:140)

at java.lang.Thread.run(Thread.java:484)

Resin 2.0.5 (built Thu Nov 15 17:56:24 PST 2001)

原因可能是:

1、你没有安装驱动程序;

2、驱动程序没有设置到系统CLASSPATH中。

解决办法:

参见 Classes Install 和 edit /etc/profile两部分

 
 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
© 2005- 王朝网络 版权所有