web.xml文件
<
servlet
>
......
< init-param >
< param-name >OracleDriver </ param-name >
< param-value >oracle.jdbc.driver.OracleDriver </ param-value >
</ init-param >
< init-param >
< param-name >Address </ param-name >
< param-value >localhost </ param-value >
</ init-param >
......
</ servlet >
......
< init-param >
< param-name >OracleDriver </ param-name >
< param-value >oracle.jdbc.driver.OracleDriver </ param-value >
</ init-param >
< init-param >
< param-name >Address </ param-name >
< param-value >localhost </ param-value >
</ init-param >
......
</ servlet >
重写init()方法,把读取web.xml的方法代码写在该方法里
@Override
public void init(ServletConfig _sysConfig) throws ServletException
{
ConfigObj = OnloadConfig(_sysConfig);
}
private WebConfig OnloadConfig(ServletConfig _sysConfig) throws ServletException,StringIndexOutOfBoundsException
{
ConfigObj.setDriveName(_sysConfig.getInitParameter( "OracleDriver"));
ConfigObj.setAddress(sysConfig.getInitParameter( "Address"));
return ConfigObj;
}
public void init(ServletConfig _sysConfig) throws ServletException
{
ConfigObj = OnloadConfig(_sysConfig);
}
private WebConfig OnloadConfig(ServletConfig _sysConfig) throws ServletException,StringIndexOutOfBoundsException
{
ConfigObj.setDriveName(_sysConfig.getInitParameter( "OracleDriver"));
ConfigObj.setAddress(sysConfig.getInitParameter( "Address"));
return ConfigObj;
}
转载于:https://blog.51cto.com/dragon514a/141884