|
Struts2 |
|
The application will display message “Struts 2 Hello World” along with current date and time of the server.
How application works?
Here is the brief description on how Struts 2 Hello World Application works:
1. When the user sends a request for the url http://localhost:8080/struts2example/javajazzup/HelloWorld.action. The container requests for the resource “HelloWorld.action”. By default web.xml file of struts blank application is configured to route all the request for *.action through org.apache.struts2.dispatcher.FilterDispatcher.
Here is the configuration from web.xml file:
<filter>
<filter-name>struts2</filter-name>
<filter-lass>
org.apache.struts2.dispatcher.FilterDispatcher
</filter-class>
</filter>
<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
2. Then the framework looks for the mapping for the action “HelloWorld” and then framework instantiates the appropriate class and calls the execute method. In this case action class is Struts2HelloWorld. Here is the configuration file from struts.xml, which defines the action mapping:
<action name=”HelloWorld”
class=”net.javajazzup.Struts2HelloWorld”>
<result>/pages/HelloWorld.jsp</result>
</action>
3. Then the execute method sets the message and returns SUCCESS. |
|
public String execute() throws Exception {
setMessage(MESSAGE);
return SUCCESS;
}
Then framework determines which page is to be loaded if SUCCESS is returned. In our case framework tells the container to load HelloWorld.jsp and render the output.
In the struts 2 framework, Actions are used to process the form and user request. The execute method of the action returns SUCCESS, ERROR, or INPUT value. Then based on these values framework tells the container to load and
render the appropriate result.
4. Container processes the HelloWorld.jsp and generates the output.
The output in the HTML format is sent to the browser.
|
|
Nov 2007 | Java Jazz Up |36 |
|
|
|
View All Topics |
All Pages of this Issue |
Pages:
1,
2,
3,
4,
5,
6,
7,
8,
9,
10,
11,
12,
13,
14,
15,
16,
17,
18,
19,
20,
21,
22,
23,
24,
25,
26,
27,
28,
29,
30,
31,
32,
33,
34,
35,
36,
37,
38,
39,
40,
41,
42,
43,
44,
45,
46,
47,
48,
49,
50,
51,
52,
53 ,
54,
55,
56,
57,
58,
59,
60,
61,
62,
63 ,
64,
65 ,
66 ,
67 ,
68 ,
69 Download PDF |
|
|
|
|
|
|
|
|
|