Now I would like to use this template in my struts 2 project (I added the struts2-jasperreport plugin in my project). I have to add the myreport.jasper but before I get rid of 2 lines that I dont need in my project. Using Struts 2 Annotations: Struts 2 supports annotation based configuration and we can use it to create action classes. To use struts 2 annotations, we need to add struts2-convention-plugin library in the classpath and in web.xml struts2 filter configuration provide the. Classical guitar blueprints wall Woodworking Projects for Beginners: Here's 50 great beginner woodworking projects that will get you comfortable with the. Make a Quick Box Using Box Joints.
Structs, an open-source Apache project at http://struts.apache.org, is a MVC (Model-View-Controller) framework for creating user interfaces for Java web application. Struts is an extension of Java Servlets and JSP. Struts is in direct competition with JSF (Java Server Faces).
[TODO] struts functions, comparison of struts and JSF.
Develop and Deploy Struts Application on Tomcat
Before writing our first Struts program, I shall assume that you have installed and configured Tomcat server. I shall also assume that Tomcat is running on port 8080 and denote the Tomcat's installed directory as
$CATALINA_HOME. (Otherwise, read 'How to install Tomcat'.)
I also assume that you understand basic Java server-side technologies such as Java Servlets, JSP (JavaServer Pages), and Java Web Applications.
Download the Struts Runtime Libraries
- Download the Struts runtime libraries from http://struts.apache.org. Select 'Downloads' ⇒ 'Releases' ⇒ Select the latest General Availability (GA) release, e.g., 'Struts 220.127.116.11' ⇒ 'Full Distribution' ⇒ '
- The runtime libraries are kept in sub-directory '
lib', which includes 71 jar-files. To deploy Struts application in Tomcat, these libraries must be available to Tomcat. You could copy the selected jar-files into Tomccat's '
lib' directory (i.e.,
$CATALINA_HOMElib), which will be available to all the web applications. You could also place the jar-files into a specific web context's '
lib' directory, which will be available to only the particular web application.
Deploy and Run the Sample Applications Provided
The downloaded Struts package contains a few ready-to-deploy sample applications in directory '
apps', in the form of war-files. In particular, a 'blank' application template for which you can use to start writing your own codes. War-file (Web Application Archive) uses ZIP algorithm to compress and group files. You can extract the contents of war-file using WINZIP, WINRAR, or any other ZIP programs.
To deploy a sample application, simply copy the war-file into Tomcat's '
webapps' directory (
$CATALINA_HOMEwebapps). Let's copy the 'blank' sample application
struts2-blank-18.104.22.168.war into Tomcat's '
webapps'. Start your Tomcat. The war-file will be unzipped and deployed automatically. Observer the following message in the Tomcat's console:
The following directories are extracted from the war-file under '
Hls streaming tool. The best free Mac video encoder here comes MacX Video Converter Free. It supports all kinds of video conversion, video compression and editing on macOS (incl. Catalina), namely decoding and encoding videos to H.265, H.264, MPEG4 or whatever codecs for WMP, QT. Use the Cube Encoder to stream HD video over WiFi, then connect the Cube Decoder to a small hAnd-held monitor or a professional field monitor to receive the signal And view video up to 1080p24. Cube™ decoders are available in both HDMI And HD-SDI versions. URayCoder HEVC H.265 H.264 SD HD 3G SDI to IP Encoder IPTV HD Video Audio Live Streaming Encoder HD-SDI Transmitter with HTTP, RTSP, UDP, SRT, HLS, ONVIF, RTMP, Multicast, Unitcast URayCoder MPEG-4 /H.264 AVC HDMI + CVBS/AV/RCA Encoder HD SD Video Audio to IP Encoder IPTV HDMI to RTMP Live Streaming Transmitter H264 with HTTP RTSP RTMP HLS.
A Java web application has a standard directory for storing various type of files:
struts2-blank-22.214.171.124': This directory is known as context root of the web application '
struts2-blank-126.96.36.199', which keeps the '
jsp' files accessible by the users. In this example, the home page '
WEB-INF': This directory is hidden from user and keeps the configuration files. You keep the configuration file in this directory and program codes in its sub-directories. In this example, it contains a configuration file '
web.xml' for configuring this web application.
WEB-INFsrc': Keep the java program source files (optional).
WEB-INFclasses': Keep the java classes.
WEB-INFlib': keep the runtime libraries (jar-files) for this application.
Start Tomcat. Observe these message in the Tomcat's console:
To access the sample struts application, issue URL
http://loaclhost:8080/struts2-blank-188.8.131.52 from a web browser. The home page '
index.html' redirect to '
exampleHelloworld.jsp'. Browse thru the source code of these pages.
http://loaclhost:8080/struts2-blank-184.108.40.206/example/Welcome.jsp, and browse thru the source codes for these pages in '
First Example: Hello-world
Let's write a Hello-world Struts application.
Define a new Web Context 'hellostructs2' in Tomcat
- First of all, define a new web context (web application) called '
hellostruts2' in Tomcat for our Struts Hello-world application, by creating the standard directory structure for the web context (as shown in the figure below). Create a directory called '
hellostruts2', under the Tomcat's
$CATALINA_HOMEwebapps). Create a sub-directory '
WEB-INF' under '
hellostruts2'. Create sub-directories: '
lib' and '
src' under '
WEB-INF'. Take note that the directory names are case-sensitive.
- Copy the struts runtime jar-file into '
Configure 'hellostruts2' - 'web.xml' and 'struts.xml'
Create the following web configuration file '
web.xml'. Save in '
<filter> tag sets up the struts's dispatcher. The
<filter-mapping> maps URL pattern '
/*' (all requests under the root) to struts.
Create the following configuration file for struts '
struts.xml'. Save in '
$CATALINA_HOMEwebappshellostruts2WEB-INFclasses'. An action called
HelloWorld is declared, which is mapped to
hello.HelloWorld class. If the action returns a string '
Success', invoke '
Write the Hello-world Struts 2 Application
input.jsp': save under the context root '
$CATALINA_HOMEwebappshellostruts2'. This page is used to produce the following form:
- The taglib directive declares the struts 2 tags, with prefix
<s:form>defines a HTML form, with processing action of '
HelloWorld'. The '
HelloWorld' action is mapped to '
hello.HelloWorld' class (in '
<s:textfield>define a text field element. The value will be captured in a field '
name' of the '
hello.HelloWorld': save as '
- To compile this Java source code using JDK, change the current directory to '
hellostruts2WEB-INF', and use
-doption to set the output directory:
- We need to define a
execute()method, which returns a string. From '
struts.xml', if the return result is '
Success', forward to '
- Two properties,
message, are defined together with the public getters and setters.
response.jsp': saved as '
hellostruts2response.jsp'. This page accesses the '
message' property of the class '
hello.HelloWorld', and has a 'Back' button to return to '
Start the Tomcat server. Check for the following messages to confirm that web context '
hellostruts2' has been started.
Run the Struts Application
Struts 2 Download
Try 'View Source' the see the output produced by '
input.jsp' and '
Front Strut Assembly
REFERENCES & RESOURCES
- Apache Tomcat @ http://tomcat.apache.org.
- Struts @ http://struts.apache.org.
- JavaServer Pages (JSP) Home Page @ http://java.sun.com/products/jsp, and Developer Site @ https://jsp.dev.java.net.
Front Struts Replacement Cost
Latest version tested: JDK 1.6, Tomcat 6.0.26, Struts 220.127.116.11
Last modified: May 1, 2010