Mettre en place vos outils de développement.
- Télécharger Eclipse IDE pour les développeurs Java EE
- Download-apache tomcat 6 Server
- TéléchargerStruts 2 jar
Après téléchargement de tous les outils, les extraire. Je suppose que vous avez déjà installé Java 6.
Créer helloWorld structure de répertoire.
- Ouvrez Eclipse IDE.
- Créer une dynamique de projet Web.
Fichier> Nouveau> Autres> Dynamic Web Project> Suite
Type "Sample" sur le projet Nom et cliquez sur Terminer
- Copie nécessaire Struts 2 fichiers jar de dossier lib.
commons-fileupload-1.2.1.jar, commons-logging-1.1.jar, freemarker-2.3.12.jar,
ognl-2.6.11.jar, struts2-core-2.1.6.jar, xwork-2.1.2.jar
- Créer les fichiers et dossiers.
> Exemples
> Java Resources: src
>> Échantillon (forfait)
>>> Helloworld.java
>> Struts.xml
> WebContent
>> Pages
>>> HelloWorld.jsp
>> WEB-INF
>>> Lib
>>>> Commons-fileupload-1.2.1.jar
>>>> Commons-logging-1.1.jar
>>>> Freemarker-2.3.12.jar
>>>> Ognl-2.6.11.jar
>>>> Struts2-core-2.1.6.jar
>>>> Xwork-2.1.2.jar
>>> Web.xml
>> Index.html
Configurez votre fichier web.xml en ajoutant le code suivant.
<? xml version = "1.0" encoding = "UTF-8"?>
<web-app
id = "WebApp_9" 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> échantillon Struts 2 </ 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.html </ welcome-file>
</ welcome-file-list>
</ web-app>
Configurez votre struts.xml en ajoutant le code suivant ci-dessous.
<? 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">
<struts>
<constant name="struts.enable.DynamicMethodInvocation" value="false"/>
<constant name="struts.devMode" value="false"/>
<package name="sample" namespace="/sample" extends="struts-default">
<action name="HelloWorld" class="sample.HelloWorld">
<result> / pages / helloWorld.jsp </ result>
</ action>
</ package>
</ struts>
Code de votre Helloworld.java en ajoutant le code suivant ci-dessous.
ensemble des échantillons;
com.opensymphony.xwork2.ActionSupport importation;
public class HelloWorld s'étend ActionSupport (
/ **
*
* /
private static final long serialVersionUID = 1L;
private String message;
public String getMessage () (
message de retour;
)
public void setMessage (String message) (
this.message = message;
)
public String execute () throws Exception (
setMessage ( "Bonjour le monde!");
return success;
)
)
Code de votre index.html en ajoutant le code suivant ci-dessous.
<! 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=utf-8">
Bonjour tout le monde <title> Application </ title>
</ head>
<body>
<div align=left> <font color="#00000"> Pour votre information, ce sont vos <b> index.html </ b> de l'WebContent directiory. </ font> </ div>
<br> <br>
<a href="sample/HelloWorld.action"> Cliquez ici </ a>
</ body>
Code de votre helloWorld.jsp en ajoutant le code suivant ci-dessous.
<% @ Page language = "java" contentType = "text / html; charset = UTF-8"
pageEncoding = "UTF-8"%>
<! DOCTYPE html PUBLIC "- / / W3C / / DTD HTML 4.01 Transitional / / EN" "http://www.w3.org/TR/html4/loose.dtd">
<% @ Taglib prefix = "s" uri = "/ struts-tags"%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title> Bonjour tout le monde </ title>
</ head>
<body>
<div align=left> <font color="#00000"> Pour votre information, ce sont vos <b> helloWorld.jsp </ b> de l'WebContent directiory. </ font> </ div>
<br>
<br>
<center> <h1> <s:property value="message"/> </ h1> </ center>
</ body>
</ html>
Exécutez le helloWorld application sur un serveur Tomcat.
- Cliquez gauche sur l'onglet Serveurs de l'EDI Eclipse.
- Clic droit> New> Server
- Sélectionnez Tomcat v6.0 Server sous Apache et gauche Cliquez sur Suivant.
- Parcourir le répertoire d'installation de Tomcat.
- Sélectionnez java-6-dimanche-1.6.0.07 et gauche Cliquez sur Terminer.
- Cliquez à gauche du projet.
- Go to Run> Run As> Exécuter sur le serveur
That's it! Eclipse navigateur apparaîtra sur votre disque IDE avec votre projet en place et fonctionne. Félicitations! Vous venez de créer votre première application Struts 2.


Delicious
Digg
Google
Yahoo