JaiswalTraining

Get the online training



Corejava Servlet Jsp  Php  Hibernate  Ajax Web Service   Ejb2.1 Ejb3.0 Struts Struts2  JPA Spring Ibatis   JSF    JSF2.0  CoreJavaDesignPattern    Jquery  Flex J2EE-Design-Patterns  Jboss7  Maven  Contact Me                                                                                                                                                                        
            IGNOU SMU PTU Project                                           Training                                                                                                                              
              

Contact Us  0091- 9210721663         jaiswaltraining@gmail.com




Corejava
Servlet
Jsp
Php
Hibernate
Ajax
Web Service
Ejb2.1
Ejb3.0
Struts  
Struts2
JPA
Spring
Ibatis
JSF
JSF2.0
CoreJavaDesignPattern
Jquery
Flex
J2EE-Design-Patterns
Jboss7
Maven







Strut2 Annotation

Overview

Struts2 has a prerequirement of Java 5 and can therefore take advantage of annotations as a
configuration mechanism.

Using annotations, the struts.xml configuration can be completely avoided in most situations.
  • Annotations rather than XML configuration: 
  • There are two benefits to using annotations:
    • first is a reduction in XML configuration. 
    • second is the configuration is closer to the
      action class (reducing the effort necessary to determine the action configuration).

Example:- This is created using eclipse IDE.

A Simple Hello World Example

Click on New --------->Dynamic Web Project



Give it any Name.....




  • Add Strut2 Library File..!
  • cright click on project----->Build Path------>Configure Build Path



  • Click on Add External jar
  • Add all neccessory Struts2 Jar files
  • Then Click on OK.
.


  • Right click on Webcontent
  • create new html file named index.jsp
index.jsp

<%taglib uri="/struts-tags" prefix="s"%>
<html>
<body>
  <s:form action="go">
    <s:submit />
  </s:form>
</body>
</html>

  • Right click on src----------> New------>package
  • create a package named my.action
  • right click on the my.action
  • Create a  class file named HelloAction.java




HelloAction.java

package my.action;

import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Result;

public class HelloAction {

  public HelloAction() {

  }

  @Action(value = "/go", results =
@Result(name = "valid", location = "/valid.jsp") })
  public String execute() throws Exception {

    return "valid";
  }

}

  • Create another jsp named valid.jsp

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <body>
      <h2>
        <font color="green">
          Hello World..............!!
        </font>
      </h2>
    </body>
</html>

Directory Structor will be


Run  the project
  • right click on project
  • click on run as------>Run On Server
Output:-

Deploying the Project



On clicking the submit button




Download Source without lib

Download War with lib