Wednesday, May 16, 2012


Spring 3.0 MVC with annoatiions



UserController.java


package com.jsl.springmvc.example;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

@Controller
public class UserController{

    @RequestMapping("/login")
    public String login(Model model){
       model.addAttribute("message","login method is invoked");
       return "viewMessage";
    }

    @RequestMapping("/viewList")
    public String viewList(Model model){
       model.addAttribute("message","viewList method is invoked");
       return "viewMessage";
    }

    @RequestMapping("/search")
    public String search(Model model){
       model.addAttribute("message","Search method is invoked");
       return "viewMessage";
    }

   @RequestMapping("/home")
   public ModelAndView home(){
      return new ModelAndView("home");
   }
}

home.jsp


<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
   
    JSL Tech Spring MVC
 

Welcome to Spring Multiaction Controller

Login ViewList Search

viewMessage.jsp


<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>

    Method invocation method
      ${message}
      Home

web.xml




  spring_mvc

  
    welcome
    org.springframework.web.servlet.DispatcherServlet
    1
  

  
    welcome
    /
  

welcome-servlet.xml




 
  
      
      
  

No comments:

Post a Comment

Spring Boot 3 : JWT with SecurityFilterChain, AuthorizeHttpRequests, RequestMatchers

pom.xml <?xml version="1.0" encoding="UTF-8"?> <project xmlns="http://maven.apache.org/POM/4.0.0...