alvinalexander.com | career | drupal | java | mac | mysql | perl | scala | uml | unix  

Struts example source code file (example-action.jsp)

This example Struts source code file (example-action.jsp) is included in the DevDaily.com "Java Source Code Warehouse" project. The intent of this project is to help you "Learn Java by Example" TM.

Java - Struts tags/keywords

book, book, date, homer, http, iliad, iliad, map, spake, string, string, the, thus, zarathustra

The Struts example-action.jsp source code

<%
    request.setAttribute("decorator", "none");
    response.setHeader("Cache-Control","no-cache"); //HTTP 1.1
    response.setHeader("Pragma","no-cache"); //HTTP 1.0
    response.setDateHeader ("Expires", 0); //prevents caching at the proxy server
%>
<pre style="font-style: normal;">
<span class="kw">package org.apache.struts2.showcase.action;

<span class="kw">import java.util.Arrays;
<span class="kw">import java.util.Date;
<span class="kw">import java.util.HashMap;
<span class="kw">import java.util.List;
<span class="kw">import java.util.Map;

<span class="kw">import com.opensymphony.xwork2.ActionSupport;

<span class="kw">public class ExampleAction extends ActionSupport {
    <span class="kw">public static final String CONSTANT = "Struts Rocks!";
        
    <span class="kw">public static Date getCurrentDate() {
        return new Date();
    }
    
    <span class="kw">public String getName() {
        return "John Galt";
    }

    <span class="kw">public String[] getBands() {
        return new String[] { "Pink Floyd", "Metallica", "Guns & Roses" };
    }

    <span class="kw">public List<String> getMovies() {
        return Arrays.asList("Lord of the Rings", "Matrix");
    }

    <span class="kw">public Book getBook() {
        <span class="kw">return new Book("Iliad", "Homer");
    }

    <span class="kw">public Map<String, Book> getBooks() {
        Map<String, Book> books = new HashMap<String, Book>();
        books.put("Iliad", new Book("Iliad", "Homer"));
        books.put("The Republic", new Book("The Replublic", "Plato"));
        books.put("Thus Spake Zarathustra", new Book("Thus Spake Zarathustra",
            "Friedrich Nietzsche"));
        return books;
    }
}

<span class="kw">class Book {
    <span class="kw">private String title;
    <span class="kw">private String author;

    <span class="kw">public Book(String title, String author) {
        this.title = title;
        this.author = author;
    }

    <span class="kw">public String getTitle() {
        <span class="kw">return title;
    }

    <span class="kw">public void setTitle(String title) {
        this.title = title;
    }

    <span class="kw">public String getAuthor() {
        return author;
    }

    <span class="kw">public void setAuthor(String author) {
        this.author = author;
    }
}
</pre>

Other Struts examples (source code examples)

Here is a short list of links related to this Struts example-action.jsp source code file:

... this post is sponsored by my books ...

#1 New Release!

FP Best Seller

 

new blog posts

 

Copyright 1998-2021 Alvin Alexander, alvinalexander.com
All Rights Reserved.

A percentage of advertising revenue from
pages under the /java/jwarehouse URI on this website is
paid back to open source projects.