File tree Expand file tree Collapse file tree 6 files changed +112
-0
lines changed
spring-boot-modules/spring-boot-jsp/src/main
java/com/baeldung/boot/jsp
webapp/WEB-INF/jsp/course Expand file tree Collapse file tree 6 files changed +112
-0
lines changed Original file line number Diff line number Diff line change
1
+ package com .baeldung .boot .jsp .controller ;
2
+
3
+ import org .springframework .stereotype .Controller ;
4
+ import org .springframework .web .bind .annotation .GetMapping ;
5
+ import org .springframework .web .bind .annotation .RequestMapping ;
6
+
7
+ @ Controller
8
+ @ RequestMapping ("/course" )
9
+ public class WelcomeController {
10
+
11
+ @ GetMapping ("/welcome" )
12
+ public String greetingAndWelcome () {
13
+ return "course/welcome" ;
14
+ }
15
+
16
+ @ GetMapping ("/welcome-usebean" )
17
+ public String greetingAndWelcomeUseBean () {
18
+ return "course/welcome-usebean" ;
19
+ }
20
+
21
+ @ GetMapping ("/welcome-by-javabean" )
22
+ public String greetingAndWelcomeByJavaBean () {
23
+ return "course/welcome-by-javabean" ;
24
+ }
25
+ }
Original file line number Diff line number Diff line change
1
+ package com .baeldung .boot .jsp .coursewelcome ;
2
+
3
+ public class CourseWelcome {
4
+
5
+ public String greeting (String username ) {
6
+ return String .format ("Hi %s, how are you doing?" , username );
7
+ }
8
+
9
+ public static String staticWelcome (String courseName ) {
10
+ return String .format ("Welcome to Baeldung's %s course" , courseName );
11
+ }
12
+
13
+ }
Original file line number Diff line number Diff line change
1
+ package com .baeldung .boot .jsp .coursewelcome ;
2
+
3
+ public class CourseWelcomeBean {
4
+
5
+ private String username ;
6
+ private String courseName ;
7
+
8
+ public String getUsername () {
9
+ return username ;
10
+ }
11
+
12
+ public void setUsername (String username ) {
13
+ this .username = username ;
14
+ }
15
+
16
+ public String getCourseName () {
17
+ return courseName ;
18
+ }
19
+
20
+ public void setCourseName (String courseName ) {
21
+ this .courseName = courseName ;
22
+ }
23
+
24
+ public String greetingUser () {
25
+ return String .format ("Hi %s, how do you do?" , username );
26
+ }
27
+
28
+ public String welcomeMsg () {
29
+ return String .format ("Welcome to Baeldung's %s course!" , courseName );
30
+ }
31
+ }
Original file line number Diff line number Diff line change
1
+ <%@ page contentType =" text/html;charset=UTF-8" language =" java" %>
2
+ <html >
3
+ <head >
4
+ <title >Welcome to Course</title >
5
+ </head >
6
+ <body >
7
+ <p >Using jsp:useBean action with a JavaBean</p >
8
+ <jsp:useBean id =" courseWelcomeBean" class =" com.baeldung.boot.jsp.coursewelcome.CourseWelcomeBean" />
9
+ <jsp:setProperty name =" courseWelcomeBean" property =" username" value =" Eric" />
10
+ <jsp:setProperty name =" courseWelcomeBean" property =" courseName" value =" Spring Security" />
11
+ <div ><%= courseWelcomeBean. greetingUser() % > </div >
12
+ <div ><%= courseWelcomeBean. welcomeMsg() % > </div >
13
+ </body >
14
+ </html >
Original file line number Diff line number Diff line change
1
+ <html >
2
+ <head >
3
+ <title >Welcome to Course</title >
4
+ </head >
5
+ <body >
6
+ <p >Using jsp:useBean action</p >
7
+ <jsp:useBean id =" welcomeBean" class =" com.baeldung.boot.jsp.coursewelcome.CourseWelcome" />
8
+ <div >
9
+ <%= welcomeBean. greeting(" Kevin" ) % >
10
+ </div >
11
+ <div >
12
+ <%= com.baeldung.boot.jsp.coursewelcome. CourseWelcome . staticWelcome(" Java Collections" ) % >
13
+ </div >
14
+ </body >
15
+ </html >
Original file line number Diff line number Diff line change
1
+ <%@ page contentType =" text/html;charset=UTF-8" language =" java" %>
2
+ <%@ page import =" com.baeldung.boot.jsp.coursewelcome.CourseWelcome" %>
3
+ <html >
4
+ <head >
5
+ <title >Welcome to Course</title >
6
+ </head >
7
+ <body >
8
+ <%
9
+ CourseWelcome courseWelcomeObj = new CourseWelcome ();
10
+ % >
11
+ <div ><%= courseWelcomeObj. greeting(" Kai" ) % > </div >
12
+ <div ><%= CourseWelcome . staticWelcome(" Spring Boot" ) % > </div >
13
+ </body >
14
+ </html >
You can’t perform that action at this time.
0 commit comments