structs2如何java类中返回string?在jsp中显示,json传输的,总是不对,求大神指点! 3C

structs2如何java类中返回string,并在jsp中显示?

问题描述:
json传输的,返回值总是不对,我想返回message="hello, success!";
内容到jsp里面。
getJSON方法总是不进入,
是否是structs.xml配置不对,求大神指点!

<package name="m2y" extends="json-default" namespace="/manageReal">
    <action name="getMessage" class="com.LoginAction.CImgHelper"
        method="getMessage">
        <result name="success" type="json">
            <param name="message">message</param>
        </result>
    </action>

1.JAVA类
public class CImgHelper {

private String message;

public String getMessage() {
    System.out.println("hello,this is CImgHelper!");
    message="hello, success!";
    return "success";
}

public void setMessage(String message) {
    this.message = message;
}

}
2..jsp

$.getJSON("manageReal/getMessage", function(data) {
    alter(data.message);
});

图片说明

6个回答

图片说明

java 改成:return this.strMessage;
报错:
警告: Could not find action or result
No result defined for action com.LoginAction.CImgHelper and result hello, success!
at com.opensymphony.xwork2.DefaultActionInvocation.executeResult(DefaultActionInvocation.java:375)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:277)
at com.opensymphony.xwork2.interceptor.DefaultWorkflowInterceptor.doIntercept(DefaultWorkflowInterceptor.java:176)
at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:98)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248)
at com.opensymphony.xwork2.validator.ValidationInterceptor.doIntercept(ValidationInterceptor.java:263)
at org.apache.struts2.interceptor.validation.AnnotationValidationInterceptor.doIntercept(AnnotationValidationInterceptor.java:68)
at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:98)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248)
at com.opensymphony.xwork2.interceptor.ConversionErrorInterceptor.intercept(ConversionErrorInterceptor.java:133)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248)
at com.opensymphony.xwork2.interceptor.ParametersInterceptor.doIntercept(ParametersInterceptor.java:207)
at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:98)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248)
at com.opensymphony.xwork2.interceptor.ParametersInterceptor.doIntercept(ParametersInterceptor.java:207)
at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:98)

看不到你的struts.xml是怎么配置的,,

yhm_js
kikop_freedom 现在可以看到了structs.xml
4 年多之前 回复

return "hello, success!";

yhm_js
kikop_freedom 改了; 报错: 警告: Could not find action or result
4 年多之前 回复

return this.strMessage;

yhm_js
kikop_freedom java 改了; 报错: 警告: Could not find action or result
4 年多之前 回复

$.getJSON("manageReal/getMessage", function(data) { alter(data.message); });

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