diff --git a/pom.xml b/pom.xml index c153cba..cf470cf 100644 --- a/pom.xml +++ b/pom.xml @@ -9,34 +9,18 @@ 3.4.1 - com.example.struts + com.example StrutsApp 1.0.0-SNAPSHOT StrutsApp Struts application - - - - - - - - - - - - - + war 21 - 3.4.1 + 3.4.1 6.4.0 - - org.springframework.boot - spring-boot-starter - org.springframework.boot spring-boot-starter-actuator @@ -44,7 +28,6 @@ org.springframework.boot spring-boot-starter-web - 3.4.0 org.springframework.boot @@ -52,11 +35,6 @@ runtime true - - org.projectlombok - lombok - true - org.springframework.boot spring-boot-starter-test @@ -70,62 +48,15 @@ jakarta.servlet jakarta.servlet-api - 6.1.0 provided - - jakarta.servlet.jsp.jstl - jakarta.servlet.jsp.jstl-api - 3.0.2 - - - org.apache.struts - struts2-spring-plugin - ${struts.version} - - - org.apache.struts - struts2-convention-plugin - ${struts.version} - - - com.guicedee.services - slf4j - 1.2.2.1 - - - org.apache.logging.log4j - log4j-core - 2.24.2 - - - org.apache.maven.plugins - maven-compiler-plugin - - - - org.projectlombok - lombok - - - - org.springframework.boot spring-boot-maven-plugin - - - - org.projectlombok - lombok - - - - - + \ No newline at end of file diff --git a/src/main/java/com/example/struts/StrutsApplication.java b/src/main/java/com/example/StrutsApplication.java similarity index 90% rename from src/main/java/com/example/struts/StrutsApplication.java rename to src/main/java/com/example/StrutsApplication.java index 87a9a0f..b4b8e66 100644 --- a/src/main/java/com/example/struts/StrutsApplication.java +++ b/src/main/java/com/example/StrutsApplication.java @@ -1,4 +1,4 @@ -package com.example.struts; +package com.example; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; diff --git a/src/main/java/com/example/action/HelloAction.java b/src/main/java/com/example/action/HelloAction.java new file mode 100644 index 0000000..3899c48 --- /dev/null +++ b/src/main/java/com/example/action/HelloAction.java @@ -0,0 +1,42 @@ +package com.example.action; + +import org.springframework.stereotype.Component; + +import com.opensymphony.xwork2.ActionSupport; + +public class HelloAction extends ActionSupport { + private static final long serialVersionUID = 1L; + + private String message = "display hello struts based action"; + + /** + * @return the message + */ + public String getMessage() { + return message; + } + + /** + * @param message the message to set + */ + public void setMessage(String message) { + this.message = message; + } + + /** + * @return the serialversionuid + */ + public static long getSerialversionuid() { + return serialVersionUID; + } + + @Override + public String execute() { + this.message = "view model is defined"; + return SUCCESS; + } + + public String displayResult() { + return "serial version is: " + getSerialversionuid() + " while message value is: " + getMessage(); + } +} \ No newline at end of file diff --git a/src/main/java/com/example/controller/HelloController.java b/src/main/java/com/example/controller/HelloController.java new file mode 100644 index 0000000..68ce3e6 --- /dev/null +++ b/src/main/java/com/example/controller/HelloController.java @@ -0,0 +1,25 @@ +package com.example.controller; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.GetMapping; +import com.example.action.HelloAction; + +@Controller +public class HelloController { + + /* + * @Autowired private HelloAction helloAction; + * + * public HelloController(HelloAction action) { this.helloAction = action; } + */ + + @GetMapping("/view") + public String helloStruts() { + System.out.println("controller HelloController called sucessfully"); + + //this.helloAction.execute(); + + return "forward:/helloStruts"; + } +} \ No newline at end of file diff --git a/src/main/java/com/example/debugging/BeanDebugger.java b/src/main/java/com/example/debugging/BeanDebugger.java new file mode 100644 index 0000000..b9aa8ac --- /dev/null +++ b/src/main/java/com/example/debugging/BeanDebugger.java @@ -0,0 +1,29 @@ +/** + * + */ +package com.example.debugging; + +import java.util.Arrays; +import org.springframework.boot.CommandLineRunner; +import org.springframework.context.ApplicationContext; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; + +@Configuration +public class BeanDebugger { + + @Bean + public CommandLineRunner debugBeans(ApplicationContext ctx) { + return args -> { + + System.out.println("Let's inspect the beans provided by Spring Boot:"); + + String[] beanNames = ctx.getBeanDefinitionNames(); + Arrays.sort(beanNames); + for (String beanName : beanNames) { + System.out.println(beanName); + } + + }; + } +} diff --git a/src/main/java/com/example/package-info.java b/src/main/java/com/example/package-info.java new file mode 100644 index 0000000..de9d613 --- /dev/null +++ b/src/main/java/com/example/package-info.java @@ -0,0 +1 @@ +package com.example; \ No newline at end of file diff --git a/src/main/java/com/example/struts/HelloController.java b/src/main/java/com/example/struts/HelloController.java deleted file mode 100644 index e1b7d76..0000000 --- a/src/main/java/com/example/struts/HelloController.java +++ /dev/null @@ -1,22 +0,0 @@ -/** - * - */ -package com.example.struts; - -import org.springframework.stereotype.Controller; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.servlet.ModelAndView; -import jakarta.servlet.http.HttpServletRequest; -import jakarta.servlet.http.HttpServletResponse; - -/** - * - */ -@Controller -public class HelloController { - - @GetMapping("/hello") - public String accessHelloPage(ModelAndView model, HttpServletRequest request, HttpServletResponse response) { - return "redirect:/hello.action"; - } -} diff --git a/src/main/java/com/example/struts/actions/HelloAction.java b/src/main/java/com/example/struts/actions/HelloAction.java deleted file mode 100644 index 911ed42..0000000 --- a/src/main/java/com/example/struts/actions/HelloAction.java +++ /dev/null @@ -1,27 +0,0 @@ -package com.example.struts.actions; - -import com.opensymphony.xwork2.ActionSupport; -import org.apache.struts2.convention.annotation.Action; -import org.apache.struts2.convention.annotation.Namespace; -import org.apache.struts2.convention.annotation.Result; -import org.springframework.stereotype.Controller; - -@Controller -@Namespace("/") -public class HelloAction extends ActionSupport { - private String message; - - @Action(value = "hello", results = { @Result(name = "success", location = "/views/hello.jsp") }) - public String get() { - message = "Hello from Struts Action!"; - return SUCCESS; - } - - public String getMessage() { - return message; - } - - public void setMessage(String message) { - this.message = message; - } -} \ No newline at end of file diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties index 24ecb64..e2113e6 100644 --- a/src/main/resources/application.properties +++ b/src/main/resources/application.properties @@ -1,4 +1,5 @@ spring.application.name=StrutsApp +spring.mvc.view.prefix=/WEB-INF/views/ +spring.mvc.view.suffix=.jsp server.port=8080 -server.servlet.context-path=/hello logging.level.web=debug \ No newline at end of file diff --git a/src/main/resources/struts.xml b/src/main/resources/struts.xml deleted file mode 100644 index b6f816c..0000000 --- a/src/main/resources/struts.xml +++ /dev/null @@ -1,14 +0,0 @@ - - - - - - views/index.jsp - - - views/hello.jsp - - - \ No newline at end of file diff --git a/src/main/webapp/WEB-INF/struts.xml b/src/main/webapp/WEB-INF/struts.xml new file mode 100644 index 0000000..c534236 --- /dev/null +++ b/src/main/webapp/WEB-INF/struts.xml @@ -0,0 +1,8 @@ + + + + + /WEB-INF/views/view.jsp + + + \ No newline at end of file diff --git a/src/main/webapp/views/index.jsp b/src/main/webapp/WEB-INF/views/index.jsp similarity index 100% rename from src/main/webapp/views/index.jsp rename to src/main/webapp/WEB-INF/views/index.jsp diff --git a/src/main/webapp/WEB-INF/views/view.jsp b/src/main/webapp/WEB-INF/views/view.jsp new file mode 100644 index 0000000..6c1bb5f --- /dev/null +++ b/src/main/webapp/WEB-INF/views/view.jsp @@ -0,0 +1,10 @@ +<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %> + + + + Hello Struts + + +

Hello, Struts!

+ + \ No newline at end of file diff --git a/src/main/webapp/WEB-INF/web.xml b/src/main/webapp/WEB-INF/web.xml index f11d6a2..e02a624 100644 --- a/src/main/webapp/WEB-INF/web.xml +++ b/src/main/webapp/WEB-INF/web.xml @@ -5,19 +5,19 @@ version="3.0"> Struts demonstration + + + org.springframework.web.context.ContextLoaderListener + - - struts2 - org.apache.struts2.dispatcher.filter.StrutsPrepareAndExecuteFilter - - - - struts2 - /* - + + struts2 + org.apache.struts2.dispatcher.filter.StrutsPrepareAndExecuteFilter + - - org.springframework.web.context.ContextLoaderListener - + + struts2 + /* + diff --git a/src/main/webapp/views/hello.jsp b/src/main/webapp/views/hello.jsp deleted file mode 100644 index 368cb0c..0000000 --- a/src/main/webapp/views/hello.jsp +++ /dev/null @@ -1,17 +0,0 @@ - -<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %> -<%@ taglib prefix="s" uri="/struts-tags" %> - - - - -Hello Page - - -

- I've said hello - - times! -

- - \ No newline at end of file