S2SH整合FreeMarker

Unable to load configuration. - bean - jar:file:/D:/apache-tomcat-6.0.32/webapps/s2shf/WEB-INF/lib/struts2-core-2.1.8.jar!/struts-default.xml:29:72

    at org.apache.struts2.dispatcher.Dispatcher.init(Dispatcher.java:431)

    at org.apache.struts2.dispatcher.ng.InitOperations.initDispatcher(InitOperations.java:69)

    at org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter.init(StrutsPrepareAndExecuteFilter.java:51)

    at org.apache.catalina.core.ApplicationFilterConfig.getFilter(ApplicationFilterConfig.java:295)

    at org.apache.catalina.core.ApplicationFilterConfig.setFilterDef(ApplicationFilterConfig.java:422)

    at org.apache.catalina.core.ApplicationFilterConfig.<init>(ApplicationFilterConfig.java:115)

    at org.apache.catalina.core.StandardContext.filterStart(StandardContext.java:4071)

    at org.apache.catalina.core.StandardContext.start(StandardContext.java:4725)

    at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:799)

    at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:779)

    at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:601)

    at org.apache.catalina.startup.HostConfig.deployDirectory(HostConfig.java:1079)

    at org.apache.catalina.startup.HostConfig.deployDirectories(HostConfig.java:1002)

    at org.apache.catalina.startup.HostConfig.deployApps(HostConfig.java:506)

    at org.apache.catalina.startup.HostConfig.start(HostConfig.java:1315)

    at org.apache.catalina.startup.HostConfig.lifecycleEvent(HostConfig.java:324)

    at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:142)

    at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1061)

    at org.apache.catalina.core.StandardHost.start(StandardHost.java:840)

    at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1053)

    at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:463)

    at org.apache.catalina.core.StandardService.start(StandardService.java:525)

    at org.apache.catalina.core.StandardServer.start(StandardServer.java:754)

    at org.apache.catalina.startup.Catalina.start(Catalina.java:595)

    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)

    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)

    at java.lang.reflect.Method.invoke(Method.java:597)

    at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:289)

    at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:414)

Caused by: Unable to load configuration. - bean - jar:file:/D:/apache-tomcat-6.0.32/webapps/s2shf/WEB-INF/lib/struts2-core-2.1.8.jar!/struts-default.xml:29:72

    at com.opensymphony.xwork2.config.ConfigurationManager.getConfiguration(ConfigurationManager.java:58)

    at org.apache.struts2.dispatcher.Dispatcher.init_PreloadConfiguration(Dispatcher.java:374)

    at org.apache.struts2.dispatcher.Dispatcher.init(Dispatcher.java:418)

    ... 29 more

Caused by: Unable to load bean: type: class:com.opensymphony.xwork2.ObjectFactory - bean - jar:file:/D:/apache-tomcat-6.0.32/webapps/s2shf/WEB-INF/lib/struts2-core-2.1.8.jar!/struts-default.xml:29:72

    at com.opensymphony.xwork2.config.providers.XmlConfigurationProvider.register(XmlConfigurationProvider.java:221)

    at org.apache.struts2.config.StrutsXmlConfigurationProvider.register(StrutsXmlConfigurationProvider.java:101)

    at com.opensymphony.xwork2.config.impl.DefaultConfiguration.reloadContainer(DefaultConfiguration.java:169)

    at com.opensymphony.xwork2.config.ConfigurationManager.getConfiguration(ConfigurationManager.java:55)

    ... 31 more

Caused by: Bean type class com.opensymphony.xwork2.ObjectFactory with the name xwork has already been loaded by bean - file:/D:/apache-tomcat-6.0.32/webapps/s2shf/WEB-INF/classes/struts-default.xml:4:72 - bean - jar:file:/D:/apache-tomcat-6.0.32/webapps/s2shf/WEB-INF/lib/struts2-core-2.1.8.jar!/struts-default.xml:29:72

    at com.opensymphony.xwork2.config.providers.XmlConfigurationProvider.register(XmlConfigurationProvider.java:205)

    ... 34 more

 jar包冲突!!!,建议用一整套无误的S2SH的jar包,然后再引入FreeMarker的jar包。

因为在struts-default.xml中,将freemarker模版type作为了默认的,所以就不需要再指定type="freemarker"了

<result-types>

            <result-type name="chain" class="com.opensymphony.xwork2.ActionChainResult"/>

            <result-type name="dispatcher" class="org.apache.struts2.dispatcher.ServletDispatcherResult"/>

            <result-type name="freemarker" class="org.apache.struts2.views.freemarker.FreemarkerResult" default="true"/>

            <result-type name="httpheader" class="org.apache.struts2.dispatcher.HttpHeaderResult"/>

            <result-type name="redirect" class="org.apache.struts2.dispatcher.ServletRedirectResult"/>

            <result-type name="redirectAction" class="org.apache.struts2.dispatcher.ServletActionRedirectResult"/>

            <result-type name="stream" class="org.apache.struts2.dispatcher.StreamResult"/>

            <result-type name="xslt" class="org.apache.struts2.views.xslt.XSLTResult"/>

            <result-type name="plainText" class="org.apache.struts2.dispatcher.PlainTextResult" />

        </result-types>

至于让我纠结了很久的问题-----freemarker标签在ftl文件中能解析,却在html文件里无法解析。在网上查了很久,引入过各种包,在xml里加过各种过滤器,还是没用

最后解决之后才发现并不要添加任何jar包、配置任何freemarker模版解析语句了。

代码如下:(在此我还将视图文件改为test.jsp  也能解析freemarker标签但是jsp标签就不能解析了,如果还需要在jsp文件中能够同时解析jsp和freemarker标签时,可以利用sitemesh ,可以参考http://www.blogjava.net/ITdavid/archive/2009/11/29/304110.html)

    public String findStu() {

        Student stu = new Student();

        stu.setAge(10);

        stu.setBirth("2013");

        stu.setStuId(1);

        stu.setStuName("sanmao");

        stu.setStuNumber("22");

        List<Student> l = new ArrayList<Student>();

        l.add(stu);

        stuList = l;

        logger.info("findStuAction stuList记录数" + stuList.size());

        this.setTplPath("/WEB-INF/templates/aaa/test.html");

        return SUCCESS;

    }

xml中配置如下:

<package name="core-struts" extends="struts-default" namespace="/">

        <action name="regist*" method="{1}" class="com.person.action.RegistAction">

            <result>${tplPath}</result>

        </action>

    </package>

如此这般就能在html使用freemarker标签了。   这根本原因就因为jar冲突或者jar引入时出现丢包的现象导致

你可能感兴趣的:(freemarker)