1、WebLogic的自启动。
A)在/etc/rc.d/init.d下创建weblogic文件,文件内容如下:
#!/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)然后进行如下处理:
chown root:root weblogic
chmod -R 777 /home/bea/
cd /etc/rc.d/init.d/
以root身份运行chkconfig --add weblogic
在linux 菜单上找到服务器设置-->服务 打开,将weblogic设为开机自动启动保存
C)weblogic 启动会比较慢,请慢慢等,也可手动启动
启动 /etc/rc.d/init.d/weblogic start
停止 /etc/rc.d/init.d/weblogic stop
重启 /etc/rc.d/init.d/weblogic restart
2、由于我们经常远程启动weblogic,当我们关闭telnet窗口后就很难取回后台。解决办法:
创建一文件run.sh。内容如下:
nohup startWebLogic.sh &
然后就可以用tail命令取回后台输出了。
tail -f nohup.out
注意out文件的路径即可。如果愿意还可以跟自启动结合使用。
我在weblogic中使用c标签,如果jsp中含有中文就会报错。
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方法分隔字符串时,分隔符如果用到一些特殊字符,可能会得不到我们预期的结果。
我们看jdk doc中说明
public String[] split(String regex)
Splits this string around matches of the given regular expression.
参数regex是一个 regular-expression的匹配模式而不是一个简单的String,他对一些特殊的字符可能会出现你预想不到的结果,比如测试下面的代码:
用竖线 | 分隔字符串,你将得不到预期的结果
String[] aa = "aaa|bbb|ccc".split("|");
//String[] aa = "aaa|bbb|ccc".split("\\|"); 这样才能得到正确的结果
for (int i = 0 ; i <aa.length ; i++ ) {
System.out.println("--"+aa[i]);
}
用竖 * 分隔字符串运行将抛出java.util.regex.PatternSyntaxException异常,用加号 + 也是如此。
String[] aa = "aaa*bbb*ccc".split("*");
//String[] aa = "aaa|bbb|ccc".split("\\*"); 这样才能得到正确的结果
for (int i = 0 ; i <aa.length ; i++ ) {
System.out.println("--"+aa[i]);
}
显然,+ * 不是有效的模式匹配规则表达式,用"\\*" "\\+"转义后即可得到正确的结果。
"|" 分隔串时虽然能够执行,但是却不是预期的目的,"\\|"转义后即可得到正确的结果。
还有如果想在串中使用"\"字符,则也需要转义.首先要表达"aaaa\bbbb"这个串就应该用"aaaa\\bbbb",如果要分隔就应该这样才能得到正确结果:
String[] aa = "aaa\\bbb\\bccc".split("\\\\");
由于本人对regular-expression理解程度不深,还望高手指正、补充。
<script>
/*
****************************
* 半角<=>全角 *
* [NB联盟] *
* Writer YuPing *
****************************
* 参数说明:
* str:要转换的字符串
* flag:标记,为0时半转全,为非0时全转半
* 返回值类型:字符串
****************************
*/
function DBC2SBC(str,flag) {
var i;
var result='';
if (str.length<=0) {alert('字符串参数出错');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联盟] *
'* Writer YuPing *
'****************************
'* 参数说明:
'* str:要转换的字符串
'* flag:标记,为0时半转全,为非0时全转半
'* 返回值类型:字符串
'****************************
function DBC2SBC(str,flag)
dim i
if len(str)<=0 then
msgbox '字符串参数出错'
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对多)
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对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"
并且其主键策略应是:
@hibernate.id
column="tea_id"
generator-class="foreign"
unsaved-value="0"
@hibernate.generator-param
name="property"
value="teacher"
另一种一头维护的1:1关系
(例如:一本书对应一个图书类型,一种图书类型对应多本书,图书类型一端不需维护对应什么书,而书的一端应维护对应哪种图书类型)
@hibernate.many-to-one
name="booktype"
column="booktype_id"
cascade="all"
not-null="true"
tomcat5中文问题,查询参数中有中文。翻下一页时会出错。
如果你是用tomcat 5.由于其在使用 get时为ISO8859-1。请设置:
打开tomcat的server.xml文件,找到区块,加入如下一行:
URIEncoding=”GBK”
完整的应如下:
<Connector
port="80" maxThreads="150" minSpareThreads="25" maxSpareThreads="75"
enableLookups="false" redirectPort="8443" acceptCount="100"
debug="0" connectionTimeout="20000"
disableUploadTimeout="true"
URIEncoding="GBK"
/>
重起tomcat
当我输入一个汉字查询时,点击查询按钮可以正确的查询出结果。但是当我在这一结果下翻页时,点击下一页valuelist就会把汉字转成乱码。经过我跟踪程序发现valuelist默认使用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搞定,可以正常的出结果了。
我在使用valuelist时发现它并没有提供针对oracle的分页(没有取当前页的数据集)功能。于是我写了一个关于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分页只读一页数据
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;
}
}
我是一个java程序员。关注java技术,希望能记录些关于java的点点滴滴。