diff --git a/pom.xml b/pom.xml index cd17b611c2..0df7dd7a9e 100644 --- a/pom.xml +++ b/pom.xml @@ -182,6 +182,7 @@ xmlunit2 xstream java-mongodb + struts2 - \ No newline at end of file + diff --git a/struts2/WebContent/WEB-INF/web.xml b/struts2/WebContent/WEB-INF/web.xml new file mode 100644 index 0000000000..3aa1d1d173 --- /dev/null +++ b/struts2/WebContent/WEB-INF/web.xml @@ -0,0 +1,16 @@ + + + MyStrutsApp + + struts2 + org.apache.struts2.dispatcher.filter.StrutsPrepareAndExecuteFilter + + + + struts2 + /* + + \ No newline at end of file diff --git a/struts2/WebContent/input.jsp b/struts2/WebContent/input.jsp new file mode 100644 index 0000000000..6d80aa3ffd --- /dev/null +++ b/struts2/WebContent/input.jsp @@ -0,0 +1,21 @@ +<%@ page language="java" contentType="text/html; charset=ISO-8859-1" + pageEncoding="ISO-8859-1"%> + + + + +Baledung Struts + + +
+

Welcome to Baeldung Struts 2 app

+

Which car do you like !!

+

Please choose ferrari or bmw

+ + +
+ + \ No newline at end of file diff --git a/struts2/WebContent/result.jsp b/struts2/WebContent/result.jsp new file mode 100644 index 0000000000..0fe9ea2d1d --- /dev/null +++ b/struts2/WebContent/result.jsp @@ -0,0 +1,11 @@ +<%@ page contentType="text/html; charset=UTF-8" %> +<%@ taglib prefix="s" uri="/struts-tags" %> + + +Hello World + + +

Hello Baeldung User

+

You are a

+ + diff --git a/struts2/pom.xml b/struts2/pom.xml new file mode 100644 index 0000000000..b6ddce6c5b --- /dev/null +++ b/struts2/pom.xml @@ -0,0 +1,44 @@ + + 4.0.0 + com.baeldung + MyStrutsApp + 0.0.1-SNAPSHOT + war + MyStrutsApp + + src + + + src + + **/*.java + + + + + + maven-compiler-plugin + 3.5.1 + + 1.8 + 1.8 + + + + maven-war-plugin + 3.0.0 + + WebContent + + + + + + + + org.apache.struts + struts2-core + 2.5.5 + + + \ No newline at end of file diff --git a/struts2/src/com/baeldung/struts/CarAction.java b/struts2/src/com/baeldung/struts/CarAction.java new file mode 100644 index 0000000000..a96aa440b6 --- /dev/null +++ b/struts2/src/com/baeldung/struts/CarAction.java @@ -0,0 +1,31 @@ +package com.baeldung.struts; + +public class CarAction { + + private String carName; + private String carMessage; + private CarMessageService carMessageService = new CarMessageService(); + + public String execute() { + System.out.println("inside execute(): carName is" + carName); + this.setCarMessage(this.carMessageService.getMessage(carName)); + return "success"; + } + + public String getCarName() { + return carName; + } + + public void setCarName(String carName) { + this.carName = carName; + } + + public String getCarMessage() { + return carMessage; + } + + public void setCarMessage(String carMessage) { + this.carMessage = carMessage; + } + +} diff --git a/struts2/src/com/baeldung/struts/CarMessageService.java b/struts2/src/com/baeldung/struts/CarMessageService.java new file mode 100644 index 0000000000..fef9c1719d --- /dev/null +++ b/struts2/src/com/baeldung/struts/CarMessageService.java @@ -0,0 +1,15 @@ +package com.baeldung.struts; + +public class CarMessageService { + + public String getMessage(String carName) { + System.out.println("inside getMessage()" + carName); + if (carName.equalsIgnoreCase("ferrari")) + return "Ferrari Fan!"; + else if (carName.equalsIgnoreCase("bmw")) + return "BMW Fan!"; + else + return "please choose ferrari Or bmw"; + } + +} diff --git a/struts2/src/struts.xml b/struts2/src/struts.xml new file mode 100644 index 0000000000..1c117ac900 --- /dev/null +++ b/struts2/src/struts.xml @@ -0,0 +1,12 @@ + + + + + + /result.jsp + + + \ No newline at end of file