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 f6aefd1

Browse files
Spring MVC Acceder a contenido estático
Servir contenido estático como imágenes, css, js, y otros, para que podamos acceder a ellos desda la vista.
1 parent 74b8f73 commit f6aefd1

File tree

9 files changed

+206
-0
lines changed

9 files changed

+206
-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_resources/pom.xml

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
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_resources</artifactId>
6+
<packaging>war</packaging>
7+
<version>1.0</version>
8+
<name>tutorial_webmvc_resources</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+
<!-- WebJars -->
39+
<dependency>
40+
<groupId>org.webjars</groupId>
41+
<artifactId>jquery</artifactId>
42+
<version>3.2.0</version>
43+
</dependency>
44+
45+
<dependency>
46+
<groupId>org.webjars</groupId>
47+
<artifactId>font-awesome</artifactId>
48+
<version>4.6.2</version>
49+
</dependency>
50+
51+
<dependency>
52+
<groupId>org.webjars</groupId>
53+
<artifactId>webjars-locator</artifactId>
54+
<version>0.31</version>
55+
</dependency>
56+
57+
<dependency>
58+
<groupId>com.fasterxml.jackson.core</groupId>
59+
<artifactId>jackson-core</artifactId>
60+
<version>2.8.8</version>
61+
</dependency>
62+
63+
</dependencies>
64+
65+
<build>
66+
<finalName>tutorial_webmvc_resources</finalName>
67+
<plugins>
68+
<plugin>
69+
<groupId>org.apache.maven.plugins</groupId>
70+
<artifactId>maven-war-plugin</artifactId>
71+
<version>2.3</version>
72+
<configuration>
73+
<failOnMissingWebXml>false</failOnMissingWebXml>
74+
</configuration>
75+
</plugin>
76+
</plugins>
77+
</build>
78+
79+
</project>
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
package carmelo.spring;
2+
3+
import java.util.concurrent.TimeUnit;
4+
import org.springframework.context.annotation.ComponentScan;
5+
import org.springframework.context.annotation.Configuration;
6+
import org.springframework.http.CacheControl;
7+
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
8+
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
9+
import org.springframework.web.servlet.config.annotation.ViewResolverRegistry;
10+
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
11+
12+
@Configuration
13+
@EnableWebMvc
14+
@ComponentScan(basePackages = {"carmelo.spring.controller"})
15+
public class WebAppConfig extends WebMvcConfigurerAdapter{
16+
17+
18+
@Override
19+
public void configureViewResolvers(ViewResolverRegistry registry) {
20+
registry.jsp("/WEB-INF/views/", ".jsp");
21+
}
22+
23+
@Override
24+
public void addResourceHandlers(ResourceHandlerRegistry registry) {
25+
registry.addResourceHandler("/static/**")
26+
.addResourceLocations("/public/", "/webjars/")
27+
.setCacheControl(CacheControl.maxAge(2, TimeUnit.DAYS))
28+
.resourceChain(true);
29+
}
30+
}
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: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package carmelo.spring.controller;
2+
3+
import org.springframework.stereotype.Controller;
4+
import org.springframework.web.bind.annotation.RequestMapping;
5+
import org.springframework.web.servlet.ModelAndView;
6+
7+
@Controller
8+
public class HomeController {
9+
10+
@RequestMapping("/")
11+
public ModelAndView homePage() {
12+
return new ModelAndView("home");
13+
}
14+
}
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: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<%@page contentType="text/html" pageEncoding="UTF-8"%>
2+
<!DOCTYPE html>
3+
<html>
4+
<head>
5+
<title>Contenido estatico</title>
6+
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
7+
8+
<link href="static/css/style.css" type="text/css" rel="stylesheet" />
9+
<link href="static/font-awesome/css/font-awesome.css" type="text/css" rel="stylesheet" />
10+
11+
<script src="static/jquery/jquery.min.js"></script>
12+
<script type="text/javascript">
13+
$(document).ready(function () {
14+
$('img').fadeOut(5000);
15+
});
16+
</script>
17+
18+
</head>
19+
<body>
20+
<h1 class="title">Tutoriales Spring Framework</h1>
21+
<img src="static/images/spring-by-pivotal.png" alt="Spring Image"/>
22+
<br />
23+
<span class="fa fa-2x fa-github">Font Awesome Icon</span>
24+
</body>
25+
</html>
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
.title {
2+
color: darkgreen;
3+
font-family: sans-serif;
4+
display: block;
5+
}
6+
7+
img {
8+
width: 400px;
9+
height: auto;
10+
}
11.7 KB
Loading[フレーム]

0 commit comments

Comments
(0)

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