0% found this document useful (0 votes)
32 views7 pages

Index

The document provides steps to create a Struts 2 web application in Eclipse Ganymede, beginning with creating a Dynamic Web Project and configuring it to use Struts 2 libraries. It includes adding Struts 2 configuration files like struts.xml and a basic HelloWorld action class and JSP. After following the 11 steps, the application displays "Hello, WebWorld!" when accessing the HelloAction URL.

Uploaded by

zahrajabari
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
32 views7 pages

Index

The document provides steps to create a Struts 2 web application in Eclipse Ganymede, beginning with creating a Dynamic Web Project and configuring it to use Struts 2 libraries. It includes adding Struts 2 configuration files like struts.xml and a basic HelloWorld action class and JSP. After following the 11 steps, the application displays "Hello, WebWorld!" when accessing the HelloAction URL.

Uploaded by

zahrajabari
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Creating Struts 2 Application on Eclipse Ganymede

Written by Wawan Hartawan


Friday, 17 October 2008 11:23 - Last Updated Thursday, 20 November 2008 10:13

After two days in deep confused how to create web application with struts 2 framework on
eclipse, finally i can get it... Alhamdullilah... :-)

I planed to create web application with the "powerfull of struts 2" and what i get... headache.. for
two days all I  got from the eclipse internal browser was warning message "There is no Action
mapped for namespace / and action name HelloWorld."

I'm looking every corner of web, and off course with the helped MR Google, and found some
usefull page,  but still i couldn't get it.   For last shot Ii tried to create application using Web
Work, the origin of Struts 2... After I made it, then I implemented the steps with Struts 2, Thank
God It's worked... The steps are...

1. I used Struts 2.1.2 with eclipse 3.4.0 Ganymede


2. First, Create New Project on Eclipse, on File -> New -> Dynamic Web Project 
3. On Project Name, fill it with project name, such as HelloWorldStruts2  then Click Next
4. Change the Java Source Directory into /WebContent/WEB-INF/classes the click finish (if
you forgot, it can be done latter from Configure Build Path Menu)
5. Copy the minimun struts 2 lib
(classworlds,common-fileuploads,common-logging,common-logging-api, freemaker, ognl, oro,
struts-core, struts2-core, xwork) into WebContent/WEB-INF/lib
6. Create new package for sample the package name is "com.hello"
7. Change web.xml file
8. Create struts.xml on classes folder "/WebContent/WEB-INF/classes"
9. Create Hello.java on com.hello package (it equal with
"/WebContent/WEB-INF/classes/com/hello" folder)
10. Create hello.jsp on WebContent (it will be influence on struts.xml) if you put the jsp file
on WEB-INF, the you must write on struts.xml result "/WEB-INF/hello.jsp"
11. Run the application
12. Put http://localhost:8080/HelloWorldStruts/Hello.action

The Code

web.xml content :

<?xml version="1.0" encoding="UTF-8"?>

1/7
Creating Struts 2 Application on Eclipse Ganymede

Written by Wawan Hartawan


Friday, 17 October 2008 11:23 - Last Updated Thursday, 20 November 2008 10:13

<web-app>

  <display-name>My Application</display-name>

  <filter>

    <filter-name>struts</filter-name>

    <filter-class>org.apache.struts2.dispatcher.FilterDispatcher</filter-class>

            <init-param>

         <param-name>actionPackages</param-name>

         <param-value>chemistry</param-value>

        </init-param>

  </filter>

  <filter-mapping>

    <filter-name>struts</filter-name>

2/7
Creating Struts 2 Application on Eclipse Ganymede

Written by Wawan Hartawan


Friday, 17 October 2008 11:23 - Last Updated Thursday, 20 November 2008 10:13

    <url-pattern>/*</url-pattern>

  </filter-mapping>

  <welcome-file-list>  

    <welcome-file>login.jsp</welcome-file>  

  </welcome-file-list>  

</web-app> 

struts.xml content :

<?xml version="1.0" encoding="UTF-8" ?>  

<!DOCTYPE struts PUBLIC  

    "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN" 

    "http://struts.apache.org/dtds/struts-2.0.dtd">   

3/7
Creating Struts 2 Application on Eclipse Ganymede

Written by Wawan Hartawan


Friday, 17 October 2008 11:23 - Last Updated Thursday, 20 November 2008 10:13

<struts>  

    <package name="com.hello" extends="struts-default">  

        <action name="Hello"  class="com.hello.Hello">  

            <result>/hello.jsp</result>  

        </action>     

    </package>  

</struts>

Hello.java

package com.hello;

import com.opensymphony.xwork2.ActionSupport;

@SuppressWarnings("serial")

4/7
Creating Struts 2 Application on Eclipse Ganymede

Written by Wawan Hartawan


Friday, 17 October 2008 11:23 - Last Updated Thursday, 20 November 2008 10:13

public class Hello extends ActionSupport{

private String message;

public String execute()

message = "Hello, WebWorld!";

return SUCCESS;

public String getMessage()

return message;

5/7
Creating Struts 2 Application on Eclipse Ganymede

Written by Wawan Hartawan


Friday, 17 October 2008 11:23 - Last Updated Thursday, 20 November 2008 10:13

hello.jsp

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"

    pageEncoding="ISO-8859-1"%>

  <%@ taglib prefix="s" uri="/struts-tags" %>  

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"


"http://www.w3.org/TR/html4/loose.dtd">

<html>

<head>

<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">

<title>Struts Pages</title>

</head>

<body>

6/7
Creating Struts 2 Application on Eclipse Ganymede

Written by Wawan Hartawan


Friday, 17 October 2008 11:23 - Last Updated Thursday, 20 November 2008 10:13

Struts Say :

<h1><s:property value="message"/></h1>

</body>

</html> 

I hope it help... 

7/7

You might also like