0

Ajax から Struts2 アクションを呼び出し、XML を使用してデータを取得する小さな例を作成しようとしています。呼び出しが実行されると、javax.xml.transform.TransformerException(以下に示す) が返されます。最終的には、Ajax 呼び出しから返されるデータ XML から name プロパティを取得したいと考えています。

ここではおそらく単純なものが欠けていますが、何が欠けているのか途方に暮れています。

struts.xml からの私のアクション:

<action name="AjaxFormSubmit" class="test.FormSubmit" >
    <result type="xslt">
        <param name="exposedValue">fName</param>
    </result>
</action>

Javascript:

$.ajax({
    url: "AjaxFormSubmit.action",
    error: function( data )
    {
        alert( "error" );
        alert( data );
    },
    success: function( data )
    {
        alert( "success" );
        alert( data );
    }
});

私のアクションクラス:

public class FormSubmit extends ActionSupport {

    public FormSubmit()
    {
        System.out.println( "in FormSubmit constructor" );
    }

    private String fName;

    public String getFName() {
        return fName;
    }

    public void setFName(String fName) {
        System.out.println( "setting fName: " + fName );
        this.fName = fName;
    }

    public String execute() throws Exception
    {
        System.out.println( "in execute" );

        return SUCCESS;
    }
}

例外:

Aug 9, 2012 1:32:20 PM com.opensymphony.xwork2.util.logging.commons.CommonsLogger error
SEVERE: Unable to render XSLT Template, 'null'
Error transforming result - [unknown location]
    at org.apache.struts2.views.xslt.XSLTResult$1.error(XSLTResult.java:351)
    at com.sun.org.apache.xalan.internal.xsltc.trax.TransformerImpl.postErrorToListener(TransformerImpl.java:788)
    at com.sun.org.apache.xalan.internal.xsltc.trax.TransformerImpl.transform(TransformerImpl.java:731)
    at com.sun.org.apache.xalan.internal.xsltc.trax.TransformerImpl.transform(TransformerImpl.java:336)
    at org.apache.struts2.views.xslt.XSLTResult.execute(XSLTResult.java:392)
    at com.opensymphony.xwork2.DefaultActionInvocation.executeResult(DefaultActionInvocation.java:374)
    at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:278)
    at org.apache.struts2.interceptor.debugging.DebuggingInterceptor.intercept(DebuggingInterceptor.java:256)
    at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249)
    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:249)
    at com.opensymphony.xwork2.validator.ValidationInterceptor.doIntercept(ValidationInterceptor.java:265)
    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:249)
    at com.opensymphony.xwork2.interceptor.ConversionErrorInterceptor.intercept(ConversionErrorInterceptor.java:138)
    at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249)
    at com.opensymphony.xwork2.interceptor.ParametersInterceptor.doIntercept(ParametersInterceptor.java:211)
    at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:98)
    at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249)
    at com.opensymphony.xwork2.interceptor.ParametersInterceptor.doIntercept(ParametersInterceptor.java:211)
    at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:98)
    at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249)
    at com.opensymphony.xwork2.interceptor.StaticParametersInterceptor.intercept(StaticParametersInterceptor.java:190)
    at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249)
    at org.apache.struts2.interceptor.MultiselectInterceptor.intercept(MultiselectInterceptor.java:75)
    at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249)
    at org.apache.struts2.interceptor.CheckboxInterceptor.intercept(CheckboxInterceptor.java:90)
    at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249)
    at org.apache.struts2.interceptor.FileUploadInterceptor.intercept(FileUploadInterceptor.java:243)
    at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249)
    at com.opensymphony.xwork2.interceptor.ModelDrivenInterceptor.intercept(ModelDrivenInterceptor.java:100)
    at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249)
    at com.opensymphony.xwork2.interceptor.ScopedModelDrivenInterceptor.intercept(ScopedModelDrivenInterceptor.java:141)
    at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249)
    at com.opensymphony.xwork2.interceptor.ChainingInterceptor.intercept(ChainingInterceptor.java:145)
    at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249)
    at com.opensymphony.xwork2.interceptor.PrepareInterceptor.doIntercept(PrepareInterceptor.java:171)
    at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:98)
    at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249)
    at com.opensymphony.xwork2.interceptor.I18nInterceptor.intercept(I18nInterceptor.java:176)
    at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249)
    at org.apache.struts2.interceptor.ServletConfigInterceptor.intercept(ServletConfigInterceptor.java:164)
    at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249)
    at com.opensymphony.xwork2.interceptor.AliasInterceptor.intercept(AliasInterceptor.java:192)
    at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249)
    at com.opensymphony.xwork2.interceptor.ExceptionMappingInterceptor.intercept(ExceptionMappingInterceptor.java:187)
    at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249)
    at org.apache.struts2.impl.StrutsActionProxy.execute(StrutsActionProxy.java:54)
    at org.apache.struts2.dispatcher.Dispatcher.serviceAction(Dispatcher.java:511)
    at org.apache.struts2.dispatcher.ng.ExecuteOperations.executeAction(ExecuteOperations.java:77)
    at org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter.doFilter(StrutsPrepareAndExecuteFilter.java:91)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:225)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:123)
    at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:168)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:98)
    at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:927)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:407)
    at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1001)
    at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:585)
    at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:312)
    at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
    at java.lang.Thread.run(Thread.java:680)
Caused by: javax.xml.transform.TransformerException: Operation not supported.
    ... 68 more
4

3 に答える 3

0

欠落しているのは、エラーで示されているXSLテンプレートです。

SEVERE: Unable to render XSLT Template, 'null'

xslt」結果タイプのドキュメントには、「location」パラメータがテンプレートを定義すると記載されています。

実際にXSLの結果が必要ですか、それともXMLだけが必要ですか?あなたは本当にそれを変えていますか?

于 2012-08-09T18:26:37.160 に答える
0

XSLTResultの実装が変更され、パラメータが必要になったと思いますlocation

ただし、以下の XSL ファイルを使用すると、生成された XML を表示できます。

<?xml version="1.0" encoding="UTF-8"?>
    <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
        <xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
        <xsl:template match="/">
            <xsl:copy-of select="*"/>
        </xsl:template>
    </xsl:stylesheet>
于 2012-09-07T12:42:27.763 に答える
0

これを試してみてください。Struts 2.0.14 で jsonplugin-0.32.jar を使用するのに役立ちます。それは私のために働いた。

struts.xml:

<struts>
     <package name="example" extends="json-default">
        <action name="HelloWorld" class="example.HelloWorld"  >
            <result type="json" />
        </action>
              <action name="HelloWorld1" class="example.HelloWorld"  >
            <result name="success" >example/HelloWorld.jsp</result>
        </action>
    </package>
</struts>

アクション クラス Helloworld.java:

package prabhakar;

import glb.DB;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * Prabhakar
 */
public class HelloWorld  {


    private List<StateMaster> stateList= new ArrayList<StateMaster>();
    private List<RegnMaster> regnList= new ArrayList<StateMaster>();

    private Integer stateId;
    public Integer getStateId()
    {
    return this.stateId;
    }
    public void setStateId(Integer stateId)
    {
    this.stateId=stateId;
    }
    public List<StateMaster> getStateList() {
        return stateList;
    }

    public void setStateList(List<StateMaster> stateList) {
        this.stateList = stateList;
    }
     public void setRegnList(List<RegnMaster> regnList) {
        this.regnList = regnList;
    }
    public List<RegnMaster> getRegnList() {
        return regnList;
    }

    public String execute() throws Exception {

        stateList=DB.getStateData()//
        if(stateId !=null)
          {
         regnList=DB.getRegnByStateId(stateId);
          }

        //setMessage(getText(MESSAGE));
        return "success";
    }

    /**
     * Provide default valuie for Message property.
     */

}

HelloWorld.action を直接呼び出して JSON データを表示するか、JSON データを以下のフォーム要素にバインドできます。

JSP ページ HelloWorld.jsp:

  /*
     Prabhakar
  */

<%@ page contentType="text/html; charset=UTF-8" %>

<%@ taglib prefix="s" uri="/struts-tags" %>
<script>
<%@include file="../js/jquery-1.7.1.min.js"%>
</script>
    <html>

<!-- JavaScript Plugins -->
  <script>
       function getLoad(){


       var stateId = $('#state').val();

$.getJSON('HelloWorld.action', {'stateId': stateId},
    function(data) {

           var divisionList = (data.regnList);

                var options = $("#regn");
                options.find('option')
    .remove()
    .end();
     options.append($("<option />").val("-1").text("--Select--"));
$.each(divisionList, function() {

    options.append($("<option />").val(this.regnId).text(this.regnName));
});
    }
);}
   </script>

<!-- jQuery-UI Dependent Scripts -->

    <body>
        State List <s:select name="stateId" list="stateList" id="state" listKey="stateId" onchange="getLoad()" listValue="stateName" headerKey="0" headerValue="--select--" />
        Regn List <s:select name="regnId"  list="regnList" listKey="regnId" id="regn" listValue="regnName" headerKey="0" headerValue="--select--" />
    </body>
</html>

:) :)

于 2013-05-14T12:30:30.103 に答える