| |
weblogic6.0的一些使用经验 前言: weblogic是一个性能卓越的j2ee服务器,在我国的使用者在快速增长.但现在有关它的中文资料基本没有,更没有介绍使用经验方面的。下面是本人在学习使用weblogic6.0中得到的一些经验,写出来与大家分享。
一、weblogic6.0的安装: weblogic6.0自带了jdk1.3,所以不用预先安装jdk就可以直接安装它,在win2000平台是一个exe文件,直接运行它即可;在unix平台上的安装包是一个*.bin文件,用sh运行它就可以了,最好是加 -i console的控制台选项(如果不加,可能会报classnofound等错误)如下所示: sh weblogic60_sol.bin -i console的控制台
注意:
unix系统的tmp目录(环境变量tmpdir或tmp_dir所指的路径)应有足够的空间,因为weblogic6.0安装时先解压文件到系统的tmp目录下,然后再进行安装。如果tmp目录空间不够安装会出错,这时你可以把tmpdir设到要足够空间的目录下。 如果用普通用户安装出错,可试着用root用户安装.一般是环境变量及权限的问题。 安装软件可到http://commerce.bea.com/downloads/products.jsp下载,联机文档可到http://edocs.bea.com/wls/docs61/index.html下载。
二、与oracle数据库的连接: weblogic6.0通过oracle客户端访问oracle,所以在weblogic6.0所在的机器上要正确安装oracle客户端才行。weblogic6.0对oracle提供type2的jdbc driver支持,是一些动态连接库(nt 是.dll,unix是.so)文件,在$wl_home/bin下,以oci开头的几个目录中。具体采用哪个目录下库文件,与oracle server端及client端的版本及oracle api的版本有关,可参考weblogic6.0的联机文档.要把这些库所在的路径加到系统的环境变量中,否则访问数据库时,weblogic6.0会报以下错误: java.sql.sqlexception: system.loadlibrary threw java.lang.unsatisfiedlinkerror with the message ´no weblogicoci37 in java.library.path´..... 在win2000中要加到path环境变量中,如: set path= d:/weblogic6.0/wlserver6.0/bin/oci816_7;c:/orant816/bin;%path% 在nix平台,要到系统的library path中,如在sun上,要加到ld_library_path环境变量中,方法如下: export ld_library_path=/bea/weblogic6.0/oci816_8:$oracle_home/lib 在hp平台上,要加到shlib_path环境变量中,如: export shlib_path=/bea/ weblogic6.0/lib/hpux11/oci816_8:$oracle_home/lib
三、在weblogic6.0中设置资源的访问权限 weblogic6.0几乎可以对它所管理的所有资源设置访问控制表,包括ejb、jsp、servlet、pool、jms、rmi、jndi、jdbc等等。当用户第一次访问设置了访问控制表的资源时,weblogic6.0会弹出一个对话框要求输入口令及密码,如果连输3次都不对,会返回以下错误: error 401--unauthorized xxx from rfc 2068 hypertext transfer protocol -- http/1.1: 10.4.2 401 unauthorized
对访问权限的设置有两种方式:
在weblogic6.o的控制台中设置,把结果保存到filerealm.properties中,即采用weblogic6.0的file realm.感觉对database pool,ejb等比较好用,对jsp,server及某个目录设置访问控制表比较难。我试了很多次都没成功。它可对web用户(通过浏览器访问)和普通用户(通过java客户端等访问)起作用。 在web.xml,weblogic.xml中设置,只能对web用户起作用。下面举个例子说明这种方式。 如:在一个名为orderwebapp的web application中,客户的定单文件都放到/orders目录下,只有manager能浏览该目录下的文件。其web.xml及weblogic.xml可设置如下: *************************web.xml************************* <!doctype web-app public "-//sun microsystems, inc.//dtd web application 1.2//en" "http://java.sun.com/j2ee/dtds/web-app_2_2.dtd"> <web-app> <security-constraint>
<web-resource-collection> <web-resource-name>secureorderseast</web-resource-name> <description>security constraint for resources in the orders directory</description> <url-pattern>/orders/*</url-pattern> <http-method>post</http-method> <http-method>get</http-method> </web-resource-collection>
<auth-constraint> <description>constraint for orders</description> <role-name>manager</role-name> </auth-constraint>
<user-data-constraint> <description>ssl not required</description> <transport-guarantee>none</transport-guarantee> </user-data-constraint>
</security-constraint>
<security-role> <description>managers</description> <role-name>manager</role-name> </security-role>
</web-app>
说明:<security-constraint>中定义资源的访问控制表。在<web-resource-collection>中定义资源及其存取方式;在<auth-constraint>中定义可访问该资源的角色;在 <user-data-constraint>中定义weblogic server与client之间的开始通讯时,是否采用ssl建立连接。在<security-role>中定义角色名。
*************************weblogic.xml************************* <!doctype weblogic6.0-web-app public "-//bea systems, inc.//dtd web application 6.0//en" "http://www.bea.com/servers/wls600/dtd/weblogic6.0-web-jar.dtd"> <weblogic6.0-web-app> <security-role-assignment> <security-role-assignment> <role-name> manager </role-name> <principal-name>peter</principal-name> <principal-name>bill</principal-name> </security-role-assignment> </weblogic6.0-web-app>
说明:在<security-role-assignment>定义与web.xml中定义的角色所对应的用户。这些用户必须已在weblogic6.0的控制台中定义才行。
当在浏览器中输入http://localhost:7001/orderwebapp/orders/order100.html时,weblogic6.0要求输入用户名及口令.只有peter,bill能够访问该文件. 我发现:如果没有在weblogic.xml中设置<security-role-assignment>,并在weblogic6.o的控制台中定义的用户名与web.xml中<security-role>中角色的名字一样.则该用户可以访问受保护的资源.如果在在weblogic.xml中设置了<security-role-assignment>,则与<security-role>中的角色名字一样的用户也不能访问受保护的资源,只有在<security-role-assignment>中定义的用户才可以访问受保护的资源.
四、jsp的设置及调试: 在weblogic6.0中,jsp要放到一个web application 中才能对它进行访问,对jsp的配置在weblogic.xml中,如下所示:
<!doctype weblogic6.0-web-app public "-//bea systems, inc.//dtd web application 6.0//en" "http://www.bea.com/servers/wls600/dtd/weblogic6.0-web-jar.dtd"> <weblogic6.0-web-app> <jsp-descriptor> <jsp-param> <param-name> pagecheckseconds </param-name> <param-value> 1 </param-value> </jsp-param> <jsp-param> <param-name> verbose </param-name> <param-value> true </param-value> </jsp-param> </jsp-descriptor> </weblogic6.0-web-app>
比较重要的有pagecheckseconds,设置weblogic6.0每隔多长时间检测一次jsp文件的内容是否改变,并需要重新编译,等于0,每次调用都重新编译(一般用于调试环境中),等于-1从不重新编译(一般用于运行环境中).当第一次访问某个web application下的一个jsp文件时,weblogic6.0把它编译成一个class文件并放到相应的目录下:
如果是以目录结构形式发布的web application,放到该web application的 web-inf/_tmp_war_examplesserver_examplesserver_*目录下。 如果该web applicaton是以一个war文件布置的,则放到: …/applications/.wl_temp_do_not_delete/web-inf/_tmp_war_examplesserver_examplesserver_*目录下。 在调试jsp时,为了使每次总是访问最新的页面,除了设置pagecheckseconds=0外,应该让ie不缓存该页面.设置如下: 把/工具/internet选项/常规/设置/的检察所存页面的较新版本,设为每次访问该页时都检查。如果还是不能看到最新的页面,可以到以上介绍的目录下把与该jsp对应的class文件删除,强制weblogic6.0重编译。
五、password的管理:
|
|