关于struts2-jquery-showcase-3.6.0.war部署

时间:2013-07-05 06:03:59

标签: struts2 struts2-jquery

是否有人尝试部署struts2-jquery-showcase-3.6.0.war。吗 我从

下载war文件

http://code.google.com/p/struts2-jquery/downloads/list

并将其导入eclipse和 从源jar中获得来自同一链接的来源。

目前,应用程序正常运行但

当我浏览应用程序时,我偶然发现了一个观察结果:

项目结构

enter image description here

的web.xml

  <?xml version="1.0" encoding="UTF-8"?>
<web-app id="struts2-jquery-showcase" version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">

    <display-name>Struts jQuery Plugin - Showcase</display-name>

    <filter>
        <filter-name>struts2</filter-name>
        <filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
    </filter>

    <filter-mapping>
        <filter-name>struts2</filter-name>
        <url-pattern>/*</url-pattern>
    </filter-mapping>

    <welcome-file-list>
        <welcome-file>index.jsp</welcome-file>
    </welcome-file-list>

</web-app>

的index.jsp

<% response.sendRedirect("index.action"); %>

ShowCase.java

    /*
 * Licensed to the Apache Software Foundation (ASF) under one
 * or more contributor license agreements.  See the NOTICE file
 * distributed with this work for additional information
 * regarding copyright ownership.  The ASF licenses this file
 * to you under the Apache License, Version 2.0 (the
 * "License"); you may not use this file except in compliance
 * with the License.  You may obtain a copy of the License at
 *
 *  http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing,
 * software distributed under the License is distributed on an
 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 * KIND, either express or implied.  See the License for the
 * specific language governing permissions and limitations
 * under the License.
 */

package com.jgeppert.struts2.jquery.showcase;

import java.util.HashMap;
import java.util.Map;

import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Result;

import com.opensymphony.xwork2.ActionSupport;

public class ShowCase extends ActionSupport {

    private static final long serialVersionUID = -7133848243722723891L;
    private String theme = "showcase";
    private boolean google = false;
    private boolean ajaxhistory = false;
    private Map<String, String> themes;

    @Action(value = "/index", results = { @Result(location = "index.jsp", name = "success") })

    public String execute() throws Exception {

        System.out.println("in showcase action.......");

        themes = new HashMap<String, String>();

    themes.put("cupertino", "The cupertino Theme");
    themes.put("ui-darkness", "The darkness Theme");
    themes.put("ui-lightness", "The lightness Theme");
    themes.put("redmond", "The redmond Theme");
    themes.put("smoothness", "The smoothness Theme");
    themes.put("black-tie", "The black-tie Theme");
    themes.put("blitzer", "The blitzer Theme");
    themes.put("dark-hive", "The dark-hive Theme");
    themes.put("dot-luv", "The dot-luv Theme");
    themes.put("eggplant", "The eggplant Theme");
    themes.put("excite-bike", "The excite-bike Theme");
    themes.put("flick", "The flick Theme");
    themes.put("hot-sneaks", "The hot-sneaks Theme");
    themes.put("humanity", "The humanity Theme");
    themes.put("le-frog", "The le-frog Theme");
    themes.put("mint-choc", "The mint-choc Theme");
    themes.put("overcast", "The overcast Theme");
    themes.put("pepper-grinder", "The pepper-grinder Theme");
    themes.put("south-street", "The south-street Theme");
    themes.put("start", "The start Theme");
    themes.put("sunny", "The sunny Theme");
    themes.put("swanky-purse", "The swanky-purse Theme");
    themes.put("trontastic", "The trontastic Theme");
    themes.put("vader", "The vader Theme");

    themes.put("showcase", "The custom Showcase Theme");

    return SUCCESS;
    }

    public String getTheme() {
    return theme;
    }

    public void setTheme(String theme) {
    this.theme = theme;
    }

    public Map<String, String> getThemes() {
    return themes;
    }

    public boolean isGoogle() {
    return google;
    }

    public void setGoogle(boolean google) {
    this.google = google;
    }

    public boolean isAjaxhistory() {
    return ajaxhistory;
    }

    public void setAjaxhistory(boolean ajaxhistory) {
    this.ajaxhistory = ajaxhistory;
    }
}

struts.xml中

    <?xml version="1.0" encoding="UTF-8" ?>
<!--
/*
 * Licensed to the Apache Software Foundation (ASF) under one
 * or more contributor license agreements.  See the NOTICE file
 * distributed with this work for additional information
 * regarding copyright ownership.  The ASF licenses this file
 * to you under the Apache License, Version 2.0 (the
 * "License"); you may not use this file except in compliance
 * with the License.  You may obtain a copy of the License at
 *
 *  http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing,
 * software distributed under the License is distributed on an
 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 * KIND, either express or implied.  See the License for the
 * specific language governing permissions and limitations
 * under the License.
 */
-->

<!DOCTYPE struts PUBLIC
    "-//Apache Software Foundation//DTD Struts Configuration 2.3//EN"
    "http://struts.apache.org/dtds/struts-2.3.dtd">

<struts>
    <constant name="struts.enable.DynamicMethodInvocation" value="false" />
    <constant name="struts.devMode" value="true" />
    <constant name="struts.convention.action.packages" value="com.jgeppert.struts2.jquery.showcase"/>
    <constant name="struts.convention.default.parent.package" value="json-default"/>
    <constant name="struts.custom.i18n.resources" value="messages" />


    <!-- Settings for CKEditor Image Upload -->
    <constant name="struts.ckeditor.allowUploads" value="true" /> <!-- default is false -->
    <constant name="struts.ckeditor.allowedFileExtensions" value="jpg,jpeg,png" />
    <constant name="sstruts.ckeditor.uploadFolder" value="/imageUploads" />

    <!-- include file="showcase.xml" / -->
</struts>

现在,当结果'成功'呈现时,它将重定向到文件夹'content'中存在的名为'index.jsp'的页面,即层次结构路径'WEB-INF / content / index.jsp'

我的问题是 如果在结果的location属性中未提及它,则如何将其重定向到内容文件夹中的页面?

当我让项目在调试模式下运行时,我开始了解content / index.jsp。 我搜索了整个项目,但我无法找到“内容”的痕迹..

1 个答案:

答案 0 :(得分:1)

WAR项目包含struts2-convention-plugin-2.3.14.2.jar插件

此插件允许您使用convention来消除XML配置。为此,JSP页面必须放在WEB-INF/文件夹中。

这就是struts.xml和showcase.xml没有定义动作映射的原因。

有关详细信息,请参阅http://struts.apache.org/release/2.3.x/docs/convention-plugin.html

您可以阅读:

By default, the Convention plugin assumes that all of the results are stored in WEB-INF/content. This can be changed by setting the property struts.convention.result.path in the Struts properties file to the new location.