1、WebLogic的自啟動(dòng)。
A)在/etc/rc.d/init.d下創(chuàng)建weblogic文件,文件內(nèi)容如下:
#!/bin/bash
#
# Startup script for the Apache Web Server
#
# chkconfig: - 85 15
# description: Apache is a World Wide Web server. It is used to serve \
# HTML files and CGI.
# processname: httpd
# pidfile: /var/run/httpd.pid
# config: /etc/httpd/conf/httpd.conf
# Source function library.
. /etc/rc.d/init.d/functions
# This will prevent initlog from swallowing up a pass-phrase prompt if
# mod_ssl needs a pass-phrase from the user.
INITLOG_ARGS=""
# Path to the apachectl script, server binary, and short-form for messages.
weblogic=/usr/bin/startWebLogic
prog=weblogic
RETVAL=0
# The semantics of these two functions differ from the way apachectl does
# things -- attempting to start while running is a failure, and shutdown
# when not running is also a failure. So we just do it the way init scripts
# are expected to behave here.
start() {
echo -n $"Starting $prog: "
#daemon "startWebLogic"
su - root -c "cd /root/bea812/user_projects/domains/bjstats/ && ./startWebLogic.sh &"
RETVAL=$?
echo
[ $RETVAL = 0 ] && touch /var/lock/subsys/weblogic
return $RETVAL
}
stop() {
echo -n $"Stopping $prog: "
#stopWebLogic
pid=`ps -ef | grep /root/bea812 | grep -v "grep" | awk '{print $2}'`
if [ "$pid" != "" ]
then
kill -9 $pid
else
echo "weblogic is not running."
fi;
RETVAL=$?
echo
[ $RETVAL = 0 ] && rm -f /var/lock/subsys/weblogic
}
# See how we were called.
case "$1" in
start)
start
;;
stop)
stop
;;
status)
#status "/root/bea812"
#RETVAL=$?
pid=`ps -ef | grep /root/bea812 | grep -v "grep" | awk '{print $2}'`
if [ "$pid" != "" ]
then
echo "weblogic is running."
else
echo "weblogic is not running."
fi;
;;
restart)
stop
start
;;
*)
echo $"Usage: $prog {start|stop|restart|status}"
exit 1
esac
exit $RETVAL
B)然后進(jìn)行如下處理:
chown root:root weblogic
chmod -R 777 /home/bea/
cd /etc/rc.d/init.d/
以root身份運(yùn)行chkconfig --add weblogic
在linux 菜單上找到服務(wù)器設(shè)置-->服務(wù) 打開(kāi),將weblogic設(shè)為開(kāi)機(jī)自動(dòng)啟動(dòng)保存
C)weblogic 啟動(dòng)會(huì)比較慢,請(qǐng)慢慢等,也可手動(dòng)啟動(dòng)
啟動(dòng) /etc/rc.d/init.d/weblogic start
停止 /etc/rc.d/init.d/weblogic stop
重啟 /etc/rc.d/init.d/weblogic restart
2、由于我們經(jīng)常遠(yuǎn)程啟動(dòng)weblogic,當(dāng)我們關(guān)閉telnet窗口后就很難取回后臺(tái)。解決辦法:
創(chuàng)建一文件run.sh。內(nèi)容如下:
nohup startWebLogic.sh &
然后就可以用tail命令取回后臺(tái)輸出了。
tail -f nohup.out
注意out文件的路徑即可。如果愿意還可以跟自啟動(dòng)結(jié)合使用。
我在weblogic中使用c標(biāo)簽,如果jsp中含有中文就會(huì)報(bào)錯(cuò)。
java.io.IOException: javax.servlet.jsp.JspException: The taglib validator rejected the page: "java.io.UTFDataFormatException: Invalid byte 2 of 2-byte UTF-8 sequence., "
解決方法:
<%@ page pageEncoding="GBK"%>
在使用String.split方法分隔字符串時(shí),分隔符如果用到一些特殊字符,可能會(huì)得不到我們預(yù)期的結(jié)果。
我們看jdk doc中說(shuō)明
public String[] split(String regex)
Splits this string around matches of the given regular expression.
參數(shù)regex是一個(gè) regular-expression的匹配模式而不是一個(gè)簡(jiǎn)單的String,他對(duì)一些特殊的字符可能會(huì)出現(xiàn)你預(yù)想不到的結(jié)果,比如測(cè)試下面的代碼:
用豎線 | 分隔字符串,你將得不到預(yù)期的結(jié)果
String[] aa = "aaa|bbb|ccc".split("|");
//String[] aa = "aaa|bbb|ccc".split("\\|"); 這樣才能得到正確的結(jié)果
for (int i = 0 ; i <aa.length ; i++ ) {
System.out.println("--"+aa[i]);
}
用豎 * 分隔字符串運(yùn)行將拋出java.util.regex.PatternSyntaxException異常,用加號(hào) + 也是如此。
String[] aa = "aaa*bbb*ccc".split("*");
//String[] aa = "aaa|bbb|ccc".split("\\*"); 這樣才能得到正確的結(jié)果
for (int i = 0 ; i <aa.length ; i++ ) {
System.out.println("--"+aa[i]);
}
顯然,+ * 不是有效的模式匹配規(guī)則表達(dá)式,用"\\*" "\\+"轉(zhuǎn)義后即可得到正確的結(jié)果。
"|" 分隔串時(shí)雖然能夠執(zhí)行,但是卻不是預(yù)期的目的,"\\|"轉(zhuǎn)義后即可得到正確的結(jié)果。
還有如果想在串中使用"\"字符,則也需要轉(zhuǎn)義.首先要表達(dá)"aaaa\bbbb"這個(gè)串就應(yīng)該用"aaaa\\bbbb",如果要分隔就應(yīng)該這樣才能得到正確結(jié)果:
String[] aa = "aaa\\bbb\\bccc".split("\\\\");
由于本人對(duì)regular-expression理解程度不深,還望高手指正、補(bǔ)充。
<script>
/*
****************************
* 半角<=>全角 *
* [NB聯(lián)盟] *
* Writer YuPing *
****************************
* 參數(shù)說(shuō)明:
* str:要轉(zhuǎn)換的字符串
* flag:標(biāo)記,為0時(shí)半轉(zhuǎn)全,為非0時(shí)全轉(zhuǎn)半
* 返回值類型:字符串
****************************
*/
function DBC2SBC(str,flag) {
var i;
var result='';
if (str.length<=0) {alert('字符串參數(shù)出錯(cuò)');return false;}
for(i=0;i<str.length;i++)
{ str1=str.charCodeAt(i);
if(str1<125&&!flag)
result+=String.fromCharCode(str.charCodeAt(i)+65248);
else
result+=String.fromCharCode(str.charCodeAt(i)-65248);
}
return result;
}
//示例:
alert(DBC2SBC("AAabc",0));
document.write(DBC2SBC("abcdefg",0))
</script>
<input type=text value="abcdefg" id=txt><input type=button value="變" onclick=txt.value=DBC2SBC(txt.value)>
<script language="vbscript">
'****************************
'* 半角<=>全角 *
'* [NB聯(lián)盟] *
'* Writer YuPing *
'****************************
'* 參數(shù)說(shuō)明:
'* str:要轉(zhuǎn)換的字符串
'* flag:標(biāo)記,為0時(shí)半轉(zhuǎn)全,為非0時(shí)全轉(zhuǎn)半
'* 返回值類型:字符串
'****************************
function DBC2SBC(str,flag)
dim i
if len(str)<=0 then
msgbox '字符串參數(shù)出錯(cuò)'
exit function
end if
for i=1 to len(str)
str1=asc(mid(str,i,1))
if str1>0 and str1<=125 and not flag then
dbc2sbc=dbc2sbc&chr(asc(mid(str,i,1))-23680)
else
dbc2sbc=dbc2sbc&chr(asc(mid(str,i,1))+23680)
end if
next
end function
'示例:
alert(dbc2sbc("AB",1))
</script>
xDoclet在Hibernate中的使用
Hibernate類:
@hibernate.class
table="teacher"
Hibernate子類:
@hibernate.joined-subclass
@hibernate.joined-subclass-key
column="tea_id"
主鍵:
@hibernate.id
column="tea_id"
generator-class="native"
普通屬性:
@hibernate.property
column="tea_name"
1:n(1對(duì)多)
1的一頭:
@hibernate.set
lazy="true"
cascade="all"
inverse="true"
@hibernate.collection-keycolumn="tea_id"
@hibernate.collection-one-to-manyclass="tms.Teacher.ZBJiangCheng"
多的一頭:
@hibernate.many-to-one
column="tea_id"
class="tms.Teacher.ZBTeacher"
not-null="true"
1:1(1對(duì)1)
1的一頭:
@hibernate.one-to-one name="gongzi"
class="tms.Teacher.ZBGongzi"
cascade="all"
1的另一頭:
@hibernate.one-to-one
name="teacher"
class="tms.Teacher.ZBTeacher"
constrained="true"
并且其主鍵策略應(yīng)是:
@hibernate.id
column="tea_id"
generator-class="foreign"
unsaved-value="0"
@hibernate.generator-param
name="property"
value="teacher"
另一種一頭維護(hù)的1:1關(guān)系
(例如:一本書對(duì)應(yīng)一個(gè)圖書類型,一種圖書類型對(duì)應(yīng)多本書,圖書類型一端不需維護(hù)對(duì)應(yīng)什么書,而書的一端應(yīng)維護(hù)對(duì)應(yīng)哪種圖書類型)
@hibernate.many-to-one
name="booktype"
column="booktype_id"
cascade="all"
not-null="true"
tomcat5中文問(wèn)題,查詢參數(shù)中有中文。翻下一頁(yè)時(shí)會(huì)出錯(cuò)。
如果你是用tomcat 5.由于其在使用 get時(shí)為ISO8859-1。請(qǐng)?jiān)O(shè)置:
打開(kāi)tomcat的server.xml文件,找到區(qū)塊,加入如下一行:
URIEncoding=”GBK”
完整的應(yīng)如下:
<Connector
port="80" maxThreads="150" minSpareThreads="25" maxSpareThreads="75"
enableLookups="false" redirectPort="8443" acceptCount="100"
debug="0" connectionTimeout="20000"
disableUploadTimeout="true"
URIEncoding="GBK"
/>
重起tomcat
當(dāng)我輸入一個(gè)漢字查詢時(shí),點(diǎn)擊查詢按鈕可以正確的查詢出結(jié)果。但是當(dāng)我在這一結(jié)果下翻頁(yè)時(shí),點(diǎn)擊下一頁(yè)valuelist就會(huì)把漢字轉(zhuǎn)成亂碼。經(jīng)過(guò)我跟蹤程序發(fā)現(xiàn)valuelist默認(rèn)使用utf-8。于是我在valuelist配置文件中加入
<property name="linkEncoder">
<bean class="net.mlw.vlh.web.tag.support.DefaultLinkEncoder" >
<property name="encoding">
<value>GBK</value>
</property>
</bean>
</property>
ok搞定,可以正常的出結(jié)果了。
我在使用valuelist時(shí)發(fā)現(xiàn)它并沒(méi)有提供針對(duì)oracle的分頁(yè)(沒(méi)有取當(dāng)前頁(yè)的數(shù)據(jù)集)功能。于是我寫了一個(gè)關(guān)于oracle的adapter
程序如下:
DefaultDynclassOracleAdapter.java
/**
* Copyright (c) 2004 RiseSoft
*
* gf7@163.com
*/
package net.risesoft.risereport.common.adapter.jdbc;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import net.mlw.vlh.ValueListInfo;
import net.risesoft.risereport.common.adapter.jdbc.OracleJdbcAdapter;
import net.mlw.vlh.adapter.jdbc.util.ResultSetMapGenerator;
import dynclass.BeanCreator;
/**
* @see net.mlw.vlh.adapter.jdbc.AbstractDynaJdbcAdapter
* @see net.mlw.vlh.adapter.jdbc.AbstractJdbcAdapter
*
* @author gf
* @version $Revision: 1.1 $ $Date: 2005/06/21 08:18:42 $
*/
public class DefaultDynclassOracleAdapter extends OracleJdbcAdapter
{
/**
* @see net.mlw.vlh.adapter.jdbc.AbstractJdbcAdapter#processResultSet(java.sql.ResultSet)
*/
public List processResultSet(String name, ResultSet result, int numberPerPage, ValueListInfo info) throws SQLException
{
List list = new ArrayList();
ResultSetMapGenerator bg = new ResultSetMapGenerator(result, useName, lowerCase);
for (int i = 0; result.next() && i < numberPerPage; i++)
{
try
{
Map properties = bg.generateMap();
list.add(BeanCreator.createBeanFromMap(properties));
}
catch (Exception e)
{
LOGGER.error(e);
}
}
return list;
}
}
AbstractOracleJdbcAdapter.java
/**
* Copyright (c) 2004 RiseSoft
*
* gf7@163.com
*/
package net.risesoft.risereport.common.adapter.jdbc;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.List;
import javax.sql.DataSource;
import net.mlw.vlh.DefaultListBackedValueList;
import net.mlw.vlh.ValueList;
import net.mlw.vlh.ValueListInfo;
import net.mlw.vlh.adapter.AbstractValueListAdapter;
import net.mlw.vlh.adapter.jdbc.objectWrapper.ResultSetDecorator;
import net.mlw.vlh.adapter.jdbc.util.JdbcUtil;
import net.mlw.vlh.adapter.jdbc.util.StandardStatementBuilder;
import net.mlw.vlh.adapter.jdbc.util.StatementBuilder;
import net.mlw.vlh.adapter.util.ObjectValidator;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
/**
* @see net.mlw.vlh.adapter.jdbc.objectWrapper.ResultSetDecorator
* @author gf
* @version $Revision: 1.2 $ $Date: 2005/07/10 03:58:55 $
*/
public abstract class AbstractOracleJdbcAdapter extends AbstractValueListAdapter
{
/** Commons logger. */
protected static final Log LOGGER = LogFactory
.getLog(AbstractOracleJdbcAdapter.class);
/** The sql.DataSource. * */
protected DataSource dataSource;
/** The sql to execute. * */
protected String sql;
/** The countSql to execute. * */
protected String countSql;
private boolean showSql = true;
/** The StatementBuilder to help generate a sql query. * */
protected StatementBuilder statementBuilder = new StandardStatementBuilder();
/**
* The validator for ResultSet's records.
*/
private ObjectValidator _validator = null;
public AbstractOracleJdbcAdapter()
{
}
/**
* @see net.mlw.vlh.ValueListAdapter#getValueList(java.lang.String,
* net.mlw.vlh.ValueListInfo)
*/
public ValueList getValueList(String name, ValueListInfo info)
{
// System.out.println("start date:"+new Date());
if (info.getSortingColumn() == null)
{
info.setPrimarySortColumn(getDefaultSortColumn());
info.setPrimarySortDirection(getDefaultSortDirectionInteger());
}
if (info.getPagingNumberPer() == Integer.MAX_VALUE)
{
info.setPagingNumberPer(getDefaultNumberPerPage());
}
ResultSet result = null;
Connection connection = null;
PreparedStatement statement = null;
try
{ StringBuffer countQuery=null;
StringBuffer query = new StringBuffer(sql);
connection = dataSource.getConnection();
boolean doSqlPaging = !((getAdapterType() & DO_PAGE) == 2);
//gf分頁(yè)只讀一頁(yè)數(shù)據(jù)
if(countSql!=null && countSql.trim().length()>0){
countQuery=new StringBuffer(countSql);
}else{
countQuery=new StringBuffer("select count(*) from(").append(sql).append(")");
}
int pageNumber = info.getPagingPage();
int numberPerPage = (info.getPagingNumberPer() > 0) ? info
.getPagingNumberPer() : getDefaultNumberPerPage();
if (doSqlPaging)
{
int firstRecord = (pageNumber - 1) * numberPerPage;
StringBuffer pagingSelect=new StringBuffer("");
pagingSelect.append("select * from ( select row_.*,rownum rownum_ from ( ");
pagingSelect.append(query.toString());
pagingSelect.append(" ) row_ where rownum < ").append(firstRecord+numberPerPage+1)
.append(" ) where rownum_ > ").append(firstRecord);
query=pagingSelect;
}
statement = statementBuilder.generate(connection, query, info
.getFilters(), doSqlPaging);
//LOGGER.debug(query.toString());
if (showSql)
{
System.out.println("sql: " + query.toString());
}
// System.out.println("1:"+new Date());
result = getResultSet(statement, info);
// System.out.println("2"+new Date());
List list = processResultSet(name, result,
(doSqlPaging) ? numberPerPage : Integer.MAX_VALUE, info);
// System.out.println("3"+new Date()+"countQuery="+countQuery);
statement = statementBuilder.generate(connection, countQuery, info
.getFilters(), doSqlPaging);
// System.out.println("4:"+new Date()+"countQuery="+countQuery);
result=statement.executeQuery();
// System.out.println("5"+new Date());
if (result.next()){
info.setTotalNumberOfEntries(result.getInt(1));
}else{
info.setTotalNumberOfEntries(0);
}
// System.out.println("end date:"+new Date());
return new DefaultListBackedValueList(list, info);
} catch (Exception e)
{
e.printStackTrace();
throw new RuntimeException(e);
} finally
{
JdbcUtil.close(result, statement, connection);
}
}
/**
* @param statement
* @param ValueListInfo This info will be set to validator.
* @return ResultSet (validator is null) or ResultSetDecorator (validator is
* not null)
* @throws SQLException
* @see net.mlw.vlh.adapter.util.ObjectValidator
* @see net.mlw.vlh.adapter.jdbc.objectWrapper.ResultSetDecorator
*/
private ResultSet getResultSet(PreparedStatement statement,
ValueListInfo info) throws SQLException
{
if (_validator == null)
{
return statement.executeQuery();
}
else
{
_validator.setValueListInfo(info);
return new ResultSetDecorator(statement.executeQuery(), _validator);
}
}
/**
* This method takes the result and puts the VOs in the List.
*
* @param result The ResultSet to interate through.
* @param info is ussually constant during this process, you can use it for
* passing additional parameters from controler. (Like in
* DefaultWrapperAdapter)
* @return The List of VOs.
*/
public abstract List processResultSet(String name, ResultSet result,
int numberPerPage, ValueListInfo info) throws SQLException;
/**
* @param dataSource The dataSource to set.
*/
public void setDataSource(DataSource dataSource)
{
this.dataSource = dataSource;
}
/**
* @param sql The sql to set.
*/
public void setSql(String sql)
{
this.sql = sql;
}
/**
* @param countSql The sql to set.
*/
public void setCountSql(String countSql)
{
this.countSql = countSql;
}
/**
* @param statementBuilder The statementBuilder to set.
*/
public void setStatementBuilder(StatementBuilder statementBuilder)
{
this.statementBuilder = statementBuilder;
}
/**
* @param showSql The showSql to set.
*/
public void setShowSql(boolean showSql)
{
this.showSql = showSql;
}
/**
* <p>
* If is set to not null value, it uses a special
* <code>ResultsSetDecorator<code>, that enable or
* disable filtering objects in the final valuelist.
* </p>
* <h4>NOTE:</h4>
* <p>
* It respects the total count of entries that overlap your paged
* list. Simply spoken it supports features such as paging.
* </p>
* @param objectValidator The objectValidator to set.
* The null value means that validator is disabled.
* @see net.mlw.vlh.adapter.util.ObjectValidator
* @see net.mlw.vlh.adapter.jdbc.objectWrapper.ResultSetDecorator
*/
public void setValidator(ObjectValidator objectValidator)
{
this._validator = objectValidator;
}
}
OracleJdbcAdapter.java
/**
* Copyright (c) 2004 RiseSoft
*
* gf7@163.com
*/
package net.risesoft.risereport.common.adapter.jdbc;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
/**
* This adapter handles the standard functionality of creating a query and
* execution it...
*
* net.mlw.vlh.adapter.jdbc.AbstractJdbcAdapter
*
* @author Matthew L. Wilson, Andrej Zachar
* @version $Revision: 1.1 $ $Date: 2005/06/21 08:18:42 $
*/
public abstract class OracleJdbcAdapter extends AbstractOracleJdbcAdapter
{
/** Commons logger. */
protected static final Log LOGGER = LogFactory
.getLog(OracleJdbcAdapter.class);
/** Sets weather the name of the column, or the alias of the column is used. * */
protected boolean useName = false;
protected boolean lowerCase = false;
public OracleJdbcAdapter()
{
}
/**
* Sets weather the name of the column, or the alias of the column is used.
* For example:
* <p>
* SELECT X as Y from dual; X = name Y = alias
* </p>
*
* @param useName
* true: use the name of the column false: use the name of the
* alias
*/
public void setUseName(boolean useName)
{
this.useName = useName;
}
/**
* Sets weather the name of the column should be lowecase;
*
* @param useName
*/
public void setLowerCase(boolean lowerCase)
{
this.lowerCase = lowerCase;
}
}
我是一個(gè)java程序員。關(guān)注java技術(shù),希望能記錄些關(guān)于java的點(diǎn)點(diǎn)滴滴。