首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > JAVA > J2EE开发 >

struts2连接数据库时报错,Detected AnnotationActionValidatorManager, initializing it.

2011-12-13 
struts2连接数据库时报错,Detected AnnotationActionValidatorManager, initializing it...貌似是泛类型错

struts2连接数据库时报错,Detected AnnotationActionValidatorManager, initializing it...
貌似是泛类型错误,具体的真的不知道是怎么回事

goodsAction

package sale.action;

import java.sql.SQLException;
import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import org.apache.struts2.ServletActionContext;

import sale.domain.Goods;
import sale.service.GoodsFacade;
import sale.service.GoodsFacadeImpl;



public class GoodsAction {

  private GoodsFacade goodsFacade;

Goods goods;
private int goodsId;
private List<Goods> list;
public GoodsAction() {
goodsFacade = new GoodsFacadeImpl();
}


public GoodsFacade getGFacade() {
return goodsFacade;
}


public void setGFacade(GoodsFacade facade) {
goodsFacade = facade;
}


public Goods getGoods() {
return goods;
}


public void setGoods(Goods goods) {
this.goods = goods;
}


public int getGoodsId() {
return goodsId;
}


public void setGoodsId(int goodsId) {
this.goodsId = goodsId;
}


public List<Goods> getList() {
return list;
}


public void setList(List<Goods> list) {
this.list = list;
}


public String addGoods() throws SQLException{

Goods goods=getGoods();
try{
goodsFacade.addGoods(goods);
setGoods(goods);
return"goodsSuccess";
}catch(Exception e){
e.printStackTrace();
return"goodsError";
}

}

}
---------------------------------------------
add.jsp页面

<%@ page language="java" import="java.util.*" pageEncoding="GB2312"%>
<%@ taglib prefix="s" uri="/struts-tags" %>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
  <s:head theme="ajax"/>
  </head>
  
  <body>
  <div align="center">
  <center>
<%-- 请求regValidate这个Action来进行处理,并且设置执行客户端校验--%>
<s:form action="goodsAction" method="addGoods" validate="false">
<%--加入token标签,避免重复提交--%>
<s:token />
<%--文本框标签,其中name属性指定传值参数,label属性指定该文本框标签名--%>
<s:textfield name="goods.name" label="商品名称" />
<s:textfield name="goods.warehouseId" label="仓库号" />
<s:textfield name="goods.description" label="商品描述" />
<s:textfield name="goods.number" label="数量" />
<s:textfield name="goods.cost" label="成本价" />
<s:submit value="确定" />
<s:reset value="重置" />
</s:form>
</center>
  <br>
  </div>
  </body>
</html>
---------------------------------------------
goodADOIml


package sale.persistence;

import java.sql.SQLException;
import java.util.Date;
import java.sql.*;



import sale.domain.Goods;
import sale.util.DBConnection;
import sale.util.Time;


public class GoodsDAOImpl implements GoodsDAO {

Connection conn=null;

Time now=new Time();

Statement st=null;
PreparedStatement psmt1=null;


ResultSet rs=null;

String time=now.getTime();

public void addGoods(Goods goods)
throws SQLException {
String sql="insert into Goods " +"(goodsNam,warehouseId,Description,Number,cost)"
+"values('"+goods.getGoodsNam()+"','"+goods.getWarehouseId()+"','"+goods.getDescription()+"','"+goods.getNumber()+"','"+goods.getCost()+"','"+time+"')";
try{
try {
conn=DBConnection.getDBC();
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
conn.setAutoCommit(false);
st=conn.createStatement();
st.executeUpdate(sql);
conn.commit();
}catch(SQLException e){
e.printStackTrace();
conn.rollback();
}finally{
conn.setAutoCommit(true);
st.close();
conn.close();
}

}

public void changeGoods(int goodsId) throws SQLException {
// TODO Auto-generated method stub

}

public void deleteGoods(int goodsId) throws SQLException {
// TODO Auto-generated method stub

}

public void searchGoods(int goodId) throws SQLException {
// TODO Auto-generated method stub

}

}
---------------------------------------

用了ado模式来连接数据库,数据连接应该没有问题
package sale.util;

import java.sql.*;

public class DBConnection {

private static String url="jdbc:microsoft:sqlserver://localhost:1433;databaseName=XD";
public static Connection getDBC() throws SQLException, Exception {
Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");
// 用户名为sa,密码为空
Connection conn = DriverManager.getConnection(url, "", "");
return conn;
}
}
-----------------------------------------

运行时,add.jsp显示并且填入数据正确,在提交数据时出现错误

显示

Detected AnnotationActionValidatorManager, initializing it...

请各位高手帮忙!!!!谢谢






[解决办法]
是不是struts.xml文件里没配

Java code
<result name="invalid.token">/page1error.jsp</ession
[解决办法]
报的是Detected AnnotationActionValidatorManager错误
检查一下validate.xml 或者 validate 相关配置。
[解决办法]
对象实例化出错 具体看报错信息

热点排行