Controller1
package cohttp://m.app.test;
import java.text.DateFormat;
import java.util.Date;
import java.util.Locale;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
@Controller
@RequestMapping("/hello")
public class HomeController {
@RequestMapping(value = "/login", method = RequestMethod.GET)
public String home() {
System.out.println("login.jsp");
return "login";
}
@RequestMapping(value = "/login", method = RequestMethod.GET, params = "aaa=ccc")
public String home2() {
System.out.println("login.jsp");
return "main";
}
}
Controller2
package cohttp://m.app.test;
import java.text.DateFormat;
import java.util.Date;
import java.util.Locale;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
@Controller
@RequestMapping("/test")
public class TestController {
@RequestMapping(value = "/login", method = RequestMethod.GET)
public String home() {
System.out.println("login.jsp");
return "login";
}
@RequestMapping(value = "/main", method = RequestMethod.GET)
public String main() {
System.out.println("main.jsp");
return "main";
}
}
Servlet-context.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans:beans xmlns="http://www.springframework.org/schema/mvc"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:beans="http://www.springframework.org/schema/beans"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/mvc https://www.springframework.org/schema/mvc/spring-mvc.xsd
http://www.springframework.org/schema/beans https://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context https://www.springframework.org/schema/context/spring-context.xsd">
<!-- DispatcherServlet Context: defines this servlet's request-processing infrastructure -->
<!-- Enables the Spring MVC @Controller programming model -->
<annotation-driven />
<!-- Handles HTTP GET requests for /resources/** by efficiently serving up static resources in the ${webappRoot}/resources directory -->
<resources mapping="/resources/**" location="/resources/" />
<!-- Resolves views selected for rendering by @Controllers to .jsp resources in the /WEB-INF/views directory -->
<beans:bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<beans:property name="prefix" value="/WEB-INF/views/" />
<beans:property name="suffix" value=".jsp" />
</beans:bean>
<context:component-scan base-package="cohttp://m.app.test" />
</beans:beans>
Main
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ page session="false" %>
<html>
<head>
<title>Home</title>
</head>
<body>
<h1>
main
</h1>
<P> The time on the server is ${serverTime}. </P>
<a href="login">login.jsp</a>
<a href="../hello/login">login.jsp</a>
<a href="/test/hello/login">login.jsp</a>
<a href="<%=request.getContextPath()%>/hello/login">login.jsp</a>
</body>
</html>
'단순 코드 기록 > Spring' 카테고리의 다른 글
Spring_Cookie (0) | 2024.02.13 |
---|---|
Spring_Parsing (0) | 2024.02.08 |
Spring_Root (0) | 2024.02.08 |
Spring_MVC_Repository (0) | 2024.02.08 |
Spring_MVC_Autowired (0) | 2024.02.08 |