Configurer une page d’accueil dans Struts

Configurer une page d'accueil dans Struts

Chaque site Web a besoin d'une page d'accueil ou par défaut comme point d'entrée. Voici 3 façons de configurer une page d'accueil dans Struts.

Téléchargez cet exemple de fichier de bienvenue Struts -Struts-Welcome-File-Example.zip

1. index.jsp

Le moyen le plus simple est de créer une page «index.jsp» et de la mettre au même niveau que le dossierWEB-INF, dossier racine du projet.

Accéder à la racine du projet

http://localhost:8080/StrutsExample/

Il sera par défaut index.jsp en interne.

http://localhost:8080/StrutsExample/index.jsp

2. web.xml welcome file

Déclarez unwelcome-file dans le fichier web.xml.

  
    
        /pages/Welcome.jsp
    
  

Accéder à la racine du projet

http://localhost:8080/StrutsExample/

Il sera redirigé vers le fichier welcome.jsp en interne.

http://localhost:8080/StrutsExample/pages/Welcome.jsp

web.xml




  Maven Struts Examples

  
    action
    
        org.apache.struts.action.ActionServlet
    
    
        config
        
         /WEB-INF/struts-config.xml
        
    
    1
  

  
       action
       *.do
  

  
    
        /pages/Welcome.jsp
    
  

3. JSP Forward

Créez un fichier «index.jsp» comme indiqué dans la méthode 1 et définissez une balise de transfert JSP pour la rediriger vers une autre action Struts.

index.jsp


Déclarez un chemin Web/Welcome, avec un typeForwardAction pour le transférer vers un autre fichier JSP.

struts-config.xml