Question

Has anyone tried deploying struts2-jquery-showcase-3.6.0.war . ? I download the war file from

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

and imported it in eclipse and got the source also from same link from sources jar.

Currently, application is up and running fine but

When I was having walk through of application I came across a observation:

Project structure

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>

Now when result 'success' is render it is redirecting to the page named 'index.jsp' present in folder 'content' i.e hierarchy path 'WEB-INF/content/index.jsp'

my question is How it is redirected to a page inside content folder when it is not mentioned in the location attribute of the result?

I came to know about the content/index.jsp when I made project to run in debug mode. I searched whole project but m not able to find the traces of 'content' ..

Was it helpful?

Solution

The WAR project includes the struts2-convention-plugin-2.3.14.2.jar plugin

This plugin lets you eliminate XML configuration by using convention. For this to work, JSP pages must be placed inside WEB-INF/ folder.

That's why struts.xml and showcase.xml define no action mappings.

See http://struts.apache.org/release/2.3.x/docs/convention-plugin.html for more info

You can read:

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top