用struts2+spring用json来取数据的问题

总是出现下面错误
ava.sql.SQLException: Positioned Update not supported.
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1055)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:956)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:926)
at com.mysql.jdbc.ResultSetImpl.getCursorName(ResultSetImpl.java:2093)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
查找资料说是修改struts.xml,加exclude,但是还是报这个错误

struts.xml配置

<constant name="struts.i18n.encoding" value="utf-8"></constant>

<package name="struts2" extends="struts-default">

    <global-results>
        <result name="add_success" type="redirect">/common/pub_add_success.jsp
        </result>
        <result name="del_success" type="redirect">/common/pub_del_success.jsp
        </result>
        <result name="modify_success" type="redirect">
            /common/pub_modify_success.jsp</result>
    </global-results>


    <action name="addPerson" class="personAction" method="addPerson">
    </action>

    <action name="delPerson" class="personAction" method="delPerson">
    </action>

    <action name="main" class="mainAction">
        <result name="success">/main.jsp</result>
    </action>

</package>

<package name="json" extends="json-default">
    <action name="find_foodCode" class="foodCodeAction" method="find_foodCode">
        <result type="json" >
         <param name="excludeProperties">
                 foodCodeManager
            </param>

        </result>
    </action>           

这个是spring的配置相关

scope="prototype">

    <bean id="foodCodeManager" class="com.oa.manager.impl.FoodCodeManagerImpl">
    <property name="sessionFactory" ref="sessionFactory"></property>
</bean>

这个是action类

package com.struts2.action;

import net.sf.json.JSONObject;

import org.apache.struts2.ServletActionContext;

import com.oa.PagerModel;
import com.oa.manager.FoodCodeManager;
import com.oa.model.FoodCode;
import com.opensymphony.xwork2.ActionSupport;

@SuppressWarnings("serial")
public class FoodCodeAction extends ActionSupport{

private int codeId;
private String name;
private int parentId;
private FoodCodeManager foodCodeManager;
private String result;

public String getResult() {
    return result;
}

public void setResult(String result) {
    this.result = result;
}

public int getCodeId() {
    return codeId;
}

public void setFoodCodeManager(FoodCodeManager foodCodeManager) {
    this.foodCodeManager = foodCodeManager;
}

public void setCodeId(int codeId) {
    this.codeId = codeId;
}

public String getName() {
    return name;
}

public void setName(String name) {
    this.name = name;
}

public int getParentId() {
    return parentId;
}

public void setParentId(int parentId) {
    this.parentId = parentId;
}

@Override
public String execute() throws Exception {

     PagerModel pm = foodCodeManager.findFoodCodes(parentId);

     ServletActionContext.getRequest().setAttribute("pm", pm);

    return SUCCESS;
}



public String find_foodCode() throws Exception{

    FoodCode foodCode = foodCodeManager.findFoodCode(1111);
    System.out.println(foodCode.getCodeId());
JSONObject jsonObject = JSONObject.fromObject(foodCode);
    System.out.println(jsonObject);

    return SUCCESS;


}   

}

[b]问题补充:[/b]
package com.oa.manager.impl;

import com.oa.PagerModel;
import com.oa.manager.FoodCodeManager;
import com.oa.model.FoodCode;

public class FoodCodeManagerImpl extends AbstractPagerManager implements
FoodCodeManager {

public void addFoodCode(FoodCode foodCode, int parentId) {
    if (parentId != 0) {
        foodCode.setParent((FoodCode) this.getHibernateTemplate().load(
                foodCode.getClass(), parentId));
    }
    this.getHibernateTemplate().save(foodCode);

}

public void delFoodCode(int codeId) {

    FoodCode foodCode = (FoodCode) this.getHibernateTemplate().load(
            FoodCode.class, codeId);

    if (foodCode.getChildern().size() > 0) {
        throw new RuntimeException("存在子分类,不允许删除");
    }
    this.getHibernateTemplate().delete(foodCode);
}

public FoodCode findFoodCode(int codeId) {
    return (FoodCode) this.getHibernateTemplate().load(FoodCode.class, codeId);
}

public PagerModel findFoodCodes(int parentId) {

    if (parentId == 0) {
        return this
                .searchPaginated("from FoodCode fc where fc.parent is null");
    }

    return this.searchPaginated("from FoodCode fc where fc.parent.id = ?",
            parentId);
}

public void modifyFoodCode(FoodCode foodCode) {

}

}

[b]问题补充:[/b]
还有我在dao类中把下面的方法的内容都去掉,只return SUCCESS的话,还是出这个错误
public String find_foodCode() throws Exception{

FoodCode foodCode = foodCodeManager.findFoodCode(1111); 
System.out.println(foodCode.getCodeId()); 

JSONObject jsonObject = JSONObject.fromObject(foodCode);
System.out.println(jsonObject);

    return SUCCESS; 

}

4个回答

在配置中加
foodCode

当然,你要有getFoodCode方法

从错误看,更多的好像是操作数据库的错误,能否把这块代码贴出来,错误日志更详细点

:oops:
看样子是json出了问题。FoodCode会不会有json解析不了的?

没看仔细。你用的result type。没必要加execute.
find_foodCode直接返回success试试,如果错误依旧,那说明action json解析有问题

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问