"Welcome To Ashok IT" "Spring Boot and MicroServices" Topic : SpringBootMVC First Application Date : 25/11/2024 (Session - 74) _____________________________________________________________________________________________________________________________ Last Session ============ * We completed introduction about Spring boot MVC module. * We completed first application in spring boot mvc. * Inorder to create webapplication by using spring boot mvc we need to select web starter i.e.,spring-boot-starter-web. * When we select the web starter will get another starter i.e.,spring-boot-starter-tomcat and it applicable before spring boot 3.x version * When we are developing the spring boot mvc application we no need to install & configure tomcat server because our webpplication will be deployed automatically into embedded server i.e.,tomcat server which will runs on port no:8080. * If Spring boot mvc application not able to start on 8080, we need to change the port number in application.properties i.e.,server.port=1234 Today Session ============= 1) Created the Sample Controller by adding two Request Processor Methods in Spring Boot MVC Application package com.ashokit.controller; import org.springframework.stereotype.Controller; import org.springframework.ui.Model; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.servlet.ModelAndView; @Controller public class WelcomeController { @RequestMapping(value="/wishes", method=RequestMethod.GET) public String generateWelcomeMessage(Model model) { model.addAttribute("Message", "Welcome To Ashok IT For Spring Boot MVC Development....."); return "welcome"; } @GetMapping(value = "/wishByUser") public ModelAndView generateWishesByUser(@RequestParam("username") String username) { ModelAndView mav = new ModelAndView("welcome"); mav.addObject("wishMessage",String.format("Welcome To Ashok IT For Spring Boot MVC Development ...%s", username)); return mav; } } 2) Created the welcome.jsp under the views folder welcome.jsp ========== <%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%> <%@ taglib prefix = "c" uri="http://java.sun.com/jsp/jstl/core" %> welcome.jsp
${Message} ${wishMessage}
3) Add the JSTL Dependencies & tomcat-jasper in pom.xml pom.xml ======= org.apache.tomcat tomcat-jasper 10.1.12 jakarta.servlet.jsp.jstl jakarta.servlet.jsp.jstl-api org.glassfish.web jakarta.servlet.jsp.jstl 4) Added the prefix and suffix in application.properties application.properties ====================== #changing the port no server.port=1234 # configure the prefix,suffix of view resolver spring.mvc.view.prefix=/views/ spring.mvc.view.suffix=.jsp 5) Open Application.java and right click on it choose Run as >>>> Spring Boot Application after application is started Open our favourite webbrowser and hit request using following url : http://localhost:1234/wishes In the above Request URL of Spring boot mvc application development context path(webapplication name) is not appended into request url. If we want to send request through context path(webapplication name) we need to add one entry in application.properties to specify the context path. server.servlet.context-path=/SpringBootMVC Before adding context path to our application by default context path is empty('') in such cases we need to use above request url only. After ending contextpath in application.properties make sure we need to request through context path only. Request URL : http://localhost:1234/SpringBootMvc/wishes Developing the Enquiry Form with BootStrap library ================================================== * BootStrap is Frontend framework which provides predefined the css class text-primary >>>>>>>>>>>>>> Displays text as blue color text-danger >>>>>>>>>>>>>> Displays text as red color text-success >>>>>>>>>>>>>> Displays text as Greencolor container >>>>>>>>>>>>>> Grouping the several html component into single block and all these Html elements are organized into center of webpage. * As programmer if we need to utilize the bootstrap library we just need to include bootstrap.css file into our webpage. bootstrap.css >>>>>>>>>> Original File bootstrap-min.css >>>>>>>>>> Minified File(Compressed Version) * We can link the css file into our JSP page by using html tag called +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++