Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 46330d5

Browse files
Spring MVC HandlerMapping
La interface HandlerMapping es la encargada de mapear una URL a su respectivo controlador.
1 parent b87f30f commit 46330d5

File tree

7 files changed

+178
-0
lines changed

7 files changed

+178
-0
lines changed
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project-shared-configuration>
3+
<!--
4+
This file contains additional configuration written by modules in the NetBeans IDE.
5+
The configuration is intended to be shared among all the users of project and
6+
therefore it is assumed to be part of version control checkout.
7+
Without this configuration present, some functionality in the IDE may be limited or fail altogether.
8+
-->
9+
<spring-data xmlns="http://www.netbeans.org/ns/spring-data/1">
10+
<config-files>
11+
<config-file>src/main/webapp/WEB-INF/springmvc-servlet.xml</config-file>
12+
</config-files>
13+
<config-file-groups/>
14+
</spring-data>
15+
<properties xmlns="http://www.netbeans.org/ns/maven-properties-data/1">
16+
<!--
17+
Properties that influence various parts of the IDE, especially code formatting and the like.
18+
You can copy and paste the single properties, into the pom.xml file and the IDE will pick them up.
19+
That way multiple projects can share the same settings (useful for formatting rules for example).
20+
Any value defined here will override the pom.xml file value but is only applicable to the current project.
21+
-->
22+
<org-netbeans-modules-javascript2-requirejs.enabled>true</org-netbeans-modules-javascript2-requirejs.enabled>
23+
<org-netbeans-modules-projectapi.jsf_2e_language>JSP</org-netbeans-modules-projectapi.jsf_2e_language>
24+
</properties>
25+
</project-shared-configuration>

‎tutorial_webmvc_HandlerMapping/pom.xml

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
2+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
3+
<modelVersion>4.0.0</modelVersion>
4+
<groupId>carmelo.spring</groupId>
5+
<artifactId>tutorial_webmvc_HandlerMapping</artifactId>
6+
<packaging>war</packaging>
7+
<version>1.0</version>
8+
<name>tutorial_webmvc_HandlerMapping</name>
9+
10+
<properties>
11+
<spring.version>4.3.7.RELEASE</spring.version>
12+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
13+
<maven.compiler.source>1.8</maven.compiler.source>
14+
<maven.compiler.target>1.8</maven.compiler.target>
15+
</properties>
16+
17+
<dependencies>
18+
<!-- Spring Web MVC -->
19+
<dependency>
20+
<groupId>org.springframework</groupId>
21+
<artifactId>spring-webmvc</artifactId>
22+
<version>${spring.version}</version>
23+
</dependency>
24+
25+
<!-- Java Servlet y JSP -->
26+
<dependency>
27+
<groupId>javax.servlet</groupId>
28+
<artifactId>javax.servlet-api</artifactId>
29+
<version>3.1.0</version>
30+
<scope>provided</scope>
31+
</dependency>
32+
<dependency>
33+
<groupId>javax.servlet</groupId>
34+
<artifactId>jstl</artifactId>
35+
<version>1.2</version>
36+
</dependency>
37+
38+
</dependencies>
39+
40+
<build>
41+
<finalName>tutorial_webmvc_HandlerMapping</finalName>
42+
<plugins>
43+
<plugin>
44+
<groupId>org.apache.maven.plugins</groupId>
45+
<artifactId>maven-war-plugin</artifactId>
46+
<version>2.3</version>
47+
<configuration>
48+
<failOnMissingWebXml>false</failOnMissingWebXml>
49+
</configuration>
50+
</plugin>
51+
</plugins>
52+
</build>
53+
54+
</project>
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
package carmelo.spring;
2+
3+
import carmelo.spring.controller.HomeController;
4+
import java.util.Properties;
5+
6+
import org.springframework.context.annotation.Bean;
7+
import org.springframework.context.annotation.ComponentScan;
8+
import org.springframework.context.annotation.Configuration;
9+
import org.springframework.web.servlet.HandlerMapping;
10+
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
11+
import org.springframework.web.servlet.handler.BeanNameUrlHandlerMapping;
12+
import org.springframework.web.servlet.handler.SimpleUrlHandlerMapping;
13+
import org.springframework.web.servlet.view.InternalResourceViewResolver;
14+
15+
@Configuration
16+
@EnableWebMvc
17+
@ComponentScan(basePackages = {"carmelo.spring.controller"})
18+
public class WebAppConfig {
19+
20+
@Bean
21+
public InternalResourceViewResolver viewResolver() {
22+
InternalResourceViewResolver resolver = new InternalResourceViewResolver();
23+
resolver.setPrefix("/WEB-INF/views/");
24+
resolver.setSuffix(".jsp");
25+
return resolver;
26+
}
27+
28+
@Bean
29+
public HandlerMapping handlerMapping() {
30+
Properties urlMaps = new Properties();
31+
urlMaps.put("/index.html", "homeController");
32+
33+
SimpleUrlHandlerMapping handler = new SimpleUrlHandlerMapping();
34+
handler.setMappings(urlMaps);
35+
36+
return handler;
37+
}
38+
39+
@Bean
40+
public HomeController homeController() {
41+
return new HomeController();
42+
}
43+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package carmelo.spring;
2+
3+
import org.springframework.web.servlet.support.AbstractAnnotationConfigDispatcherServletInitializer;
4+
5+
public class WebAppInitializer extends AbstractAnnotationConfigDispatcherServletInitializer {
6+
7+
@Override
8+
protected Class<?>[] getRootConfigClasses() {
9+
return null;
10+
}
11+
12+
@Override
13+
protected Class<?>[] getServletConfigClasses() {
14+
return new Class[]{WebAppConfig.class};
15+
}
16+
17+
@Override
18+
protected String[] getServletMappings() {
19+
return new String[]{"/"};
20+
}
21+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
package carmelo.spring.controller;
2+
3+
import javax.servlet.http.HttpServletRequest;
4+
import javax.servlet.http.HttpServletResponse;
5+
import org.springframework.stereotype.Controller;
6+
import org.springframework.ui.Model;
7+
import org.springframework.web.bind.annotation.RequestMapping;
8+
import org.springframework.web.servlet.ModelAndView;
9+
import org.springframework.web.servlet.mvc.AbstractController;
10+
11+
public class HomeController extends AbstractController {
12+
13+
@Override
14+
protected ModelAndView handleRequestInternal(
15+
HttpServletRequest request,
16+
HttpServletResponse response) throws Exception {
17+
18+
return new ModelAndView("home");
19+
}
20+
}
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<Context antiJARLocking="true" path="/webapp"/>
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<%@page contentType="text/html" pageEncoding="UTF-8"%>
2+
<!DOCTYPE html>
3+
<html>
4+
<head>
5+
<title>HandlerMapping</title>
6+
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
7+
</head>
8+
<body>
9+
<h1>Spring MVC :: HandlerMapping</h1>
10+
<p>Tutoriales Spring MVC by Tutor de Programacion.</p>
11+
<p>Estudiando el componente <strong>HandlerMapping</strong>.</p>
12+
</body>
13+
</html>

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /