我是新手,请帮忙看看

03-10-20 zhb
这样取DataSource为什么取出为空

ServletContext context = servlet.getServletContext();

DataSource dataSource = (DataSource)context.getAttribute(Action.DATA_SOURCE_KEY);

注:在struts-config.xml中这样定义

<data-sources>

<data-source key="dataSource">

<set-property value="org.gjt.mm.mysql.Driver" property="driverClass" />

<set-property value="jdbc:mysql://localhost/employees" property="url" />

<set-property value="5" property="maxCount" />

<set-property value="1" property="minCount" />

<set-property value="username" property="admin" />

<set-property value="password" property="admin" />

</data-source>

</data-sources>

猜你喜欢