struts.测试数据库出错.信息如下:Initializing application data .....

03-07-08 oo
测试数据库出错.信息如下:

----------------------------------------------------------------

500 Servlet Exception

javax.servlet.UnavailableException: Initializing application data source

org.apache.struts.action.DATA_SOURCE

at org.apache.struts.action.ActionServlet.initModuleDataSources(ActionServlet.java:1091)

at org.apache.struts.action.ActionServlet.init(ActionServlet.java:472)

at javax.servlet.GenericServlet.init(GenericServlet.java:82)

at com.caucho.server.http.Application.createServlet(Application.java:2755)

at com.caucho.server.http.Application.loadServlet(Application.java:2711)

at com.caucho.server.http.Application.initServlets(Application.java:1763)

at com.caucho.server.http.Application.init(Application.java:1698)

at com.caucho.server.http.VirtualHost.restartApplication(VirtualHost.java:1340)

at com.caucho.server.http.VirtualHost.getInvocation(VirtualHost.java:992)

at com.caucho.server.http.ServletServer.getInvocation(ServletServer.java:935)

at com.caucho.server.http.ServletServer.serviceTop(ServletServer.java:845)

at com.caucho.server.http.HttpRequest.handleRequest(HttpRequest.java:213)

at com.caucho.server.http.HttpRequest.handleConnection(HttpRequest.java:158)

at com.caucho.server.TcpConnection.run(TcpConnection.java:140)

at java.lang.Thread.run(Thread.java:534)

--------------------------------------------------------------------------------

Resin 2.0.4 (built Thu Nov 15 17:56:24 PST 2001)

---------------------------------------------------

struts-config.xml如下;

--------------------------

<?xml version="1.0" encoding="ISO-8859-1" ?>

<!DOCTYPE struts-config PUBLIC

"-//Apache Software Foundation//DTD Struts Configuration 1.1//EN"

"http://jakarta.apache.org/struts/dtds/struts-config_1_1.dtd">

<!--

This is the Struts configuration file for the example application,

using the proposed new syntax.

-->

<struts-config>

<!-- ========== Data Source Configuration =============================== -->

<data-sources>

<data-source>

<set-property property="autoCommit"

value="false"/>

<set-property property="description"

value="Example Data Source Configuration"/>

<set-property property="driverClass"

value="org.gjt.mm.mysql.Driver"/>

<set-property property="maxCount"

value="4"/>

<set-property property="minCount"

value="2"/>

<set-property property="password"

value="111"/>

<set-property property="url"

value="jdbc:postgresql://localhost:3306/stock"/>

<set-property property="user"

value="root"/>

</data-source>

</data-sources>

<!-- ========== form Bean Definitions =================================== -->

<form-beans>

<form-bean name="LookUpform" type="stock.LookUpform"/>

</form-beans>

<!-- ========== Action Mapping Definitions ============================== -->

<action-mappings>

<action path="/lookup"

type="stock.LookUpAction"

scope="request"

input="/index.jsp"

name="LookUpform">

<forward name="success" path="/quote.jsp"/>

<forward name="failure" path="/index.jsp"/>

</action>

</action-mappings>

<message-resources parameter="com.wiley.ApplicationResources"/>

</struts-config>

--------------------------------------------------------------

Action源码:

-----------------------------

package stock;

import javax.servlet.ServletContext;

import javax.sql.DataSource;

import java.sql.Connection;

import java.sql.ResultSet;

import java.sql.Statement;

import java.sql.SQLException;

import javax.servlet.http.HttpServletRequest;

import javax.servlet.http.HttpServletResponse;

import javax.servlet.ServletException;

import java.io.IOException;

import org.apache.struts.action.Actionform;

import org.apache.struts.action.Action;

import org.apache.struts.action.ActionForward;

import org.apache.struts.action.ActionMapping;

public class LookUpAction extends Action{

/*protected Double getQuote(String symbol){

if(symbol.equalsIgnoreCase("SUN")){

return new Double(25.00);

}

return null;

}*/

protected Double getQuote(String symbol){

Double price=null;

Connection conn=null;

Statement stmt=null;

ResultSet rs=null;

ServletContext context = servlet.getServletContext();

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

try{

conn=dataSource.getConnection();

stmt=conn.createStatement();

rs=stmt.executeQuery("select * from stocks where symbol='"+symbol+"'");

if(rs.next()){

double tmp=0;

tmp=rs.getDouble("price");

price=new Double(tmp);

System.err.println("price"+price);

}else{

System.err.println("symbol not found");

}

}catch(SQLException e){

System.err.println(e.getMessage());

}finally{

rs=null;

stmt=null;

conn=null;

}

return price;

}

public ActionForward execute(ActionMapping mapping,Actionform form,HttpServletRequest request,HttpServletResponse response) throws IOException,ServletException{

Double price=null;

String target=new String ("success");

if(form!=null){

LookUpform lookupform=(LookUpform)form;

String symbol=lookupform.getSymbol();

price=getQuote(symbol);

}

if(price==null){

target=new String ("failure");

}else{

request.setAttribute("PRICE",price);

}

return (mapping.findForward(target));

}

}

不知是何缘故..请各位帮忙...~~~

-----------------------

我用的是1.1,试了一下,换成1.0的struts.jar,不会有错误.但是LookUpActin就会没反应.不会转到相应的页面..

晕菜死了快...

oo
2003-07-08 15:56
struts-config.xml为啥老发错.再发一遍..

------------------------------------------

片段:

<struts-config>

<data-sources>

<data-source>

<set-property property="autoCommit"

value="false"/>

<set-property property="description"

value="Example Data Source Configuration"/>

<set-property property="driverClass"

value="org.gjt.mm.mysql.Driver"/>

<set-property property="maxCount"

value="4"/>

<set-property property="minCount"

value="2"/>

<set-property property="password"

value="111"/>

<set-property property="url"

value="jdbc:postgresql://localhost:3306/stock"/>

<set-property property="user"

value="root"/>

</data-source>

</data-sources>

<form-beans>

<form-bean name="LookUpform" type="stock.LookUpform"/>

</form-beans>

<action-mappings>

<action path="/lookup"

type="stock.LookUpAction"

scope="request"

input="/index.jsp"

name="LookUpform">

<forward name="success" path="/quote.jsp"/>

<forward name="failure" path="/index.jsp"/>

</action>

</action-mappings>

<message-resources parameter="com.wiley.ApplicationResources"/>

</struts-config>

猜你喜欢