Skip to content

Commit 74a2815

Browse files
Added code for question 44192253.
1 parent fa836af commit 74a2815

File tree

8 files changed

+198
-0
lines changed

8 files changed

+198
-0
lines changed

44192253/pom.xml

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
4+
<modelVersion>4.0.0</modelVersion>
5+
6+
<groupId>org.example</groupId>
7+
<artifactId>stackoverflow</artifactId>
8+
<version>1.0</version>
9+
<packaging>war</packaging>
10+
11+
<build>
12+
<plugins>
13+
<plugin>
14+
<groupId>org.apache.maven.plugins</groupId>
15+
<artifactId>maven-compiler-plugin</artifactId>
16+
<version>3.1</version>
17+
<configuration>
18+
<compilerArgument>-Xlint:none</compilerArgument>
19+
<source>${java.version}</source>
20+
<target>${java.version}</target>
21+
</configuration>
22+
</plugin>
23+
<plugin>
24+
<groupId>org.apache.tomcat.maven</groupId>
25+
<artifactId>tomcat7-maven-plugin</artifactId>
26+
<version>2.2</version>
27+
<configuration>
28+
<path>/</path>
29+
</configuration>
30+
</plugin>
31+
</plugins>
32+
</build>
33+
34+
<dependencies>
35+
<dependency>
36+
<groupId>javax.servlet</groupId>
37+
<artifactId>javax.servlet-api</artifactId>
38+
<version>3.1.0</version>
39+
<scope>provided</scope>
40+
</dependency>
41+
42+
<dependency>
43+
<groupId>org.springframework</groupId>
44+
<artifactId>spring-web</artifactId>
45+
<version>${spring.version}</version>
46+
</dependency>
47+
<dependency>
48+
<groupId>org.springframework</groupId>
49+
<artifactId>spring-webmvc</artifactId>
50+
<version>${spring.version}</version>
51+
</dependency>
52+
</dependencies>
53+
54+
<properties>
55+
<java.version>1.8</java.version>
56+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
57+
58+
<spring.version>4.3.8.RELEASE</spring.version>
59+
</properties>
60+
</project>
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package org.example.web;
2+
3+
import org.springframework.stereotype.Controller;
4+
import org.springframework.web.bind.annotation.GetMapping;
5+
6+
@Controller
7+
public class HomeController
8+
{
9+
@GetMapping("/")
10+
public String home()
11+
{
12+
return "home";
13+
}
14+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package org.example.web;
2+
3+
import org.springframework.stereotype.Controller;
4+
import org.springframework.ui.Model;
5+
import org.springframework.web.bind.annotation.GetMapping;
6+
import org.springframework.web.bind.annotation.RequestParam;
7+
8+
import java.math.BigDecimal;
9+
10+
@Controller
11+
public class LocationController
12+
{
13+
@GetMapping("/location")
14+
public String location(@RequestParam(defaultValue = "0.0") final Double latitude
15+
, @RequestParam(defaultValue = "0.0") final Double longitude
16+
, final Model model)
17+
{
18+
model.addAttribute("latitude", latitude);
19+
model.addAttribute("longitude", longitude);
20+
21+
return "location";
22+
}
23+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
3+
<beans xmlns="http://www.springframework.org/schema/beans"
4+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
5+
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">
6+
</beans>
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
3+
<beans xmlns="http://www.springframework.org/schema/beans"
4+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
5+
xmlns:context="http://www.springframework.org/schema/context"
6+
xmlns:mvc="http://www.springframework.org/schema/mvc"
7+
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
8+
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd
9+
http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd">
10+
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver" id="viewResolver">
11+
<property name="prefix" value="/page/"/>
12+
<property name="suffix" value=".jsp"/>
13+
</bean>
14+
15+
<context:annotation-config/>
16+
<context:component-scan base-package="org.example"/>
17+
18+
<mvc:annotation-driven/>
19+
</beans>
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
3+
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xmlns="http://java.sun.com/xml/ns/javaee"
5+
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
6+
version="3.0">
7+
<context-param>
8+
<param-name>contextConfigLocation</param-name>
9+
<param-value>classpath*:springContext.xml</param-value>
10+
</context-param>
11+
12+
<listener>
13+
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
14+
</listener>
15+
<listener>
16+
<listener-class>org.springframework.web.context.request.RequestContextListener</listener-class>
17+
</listener>
18+
19+
<servlet>
20+
<servlet-name>spring-mvc-dispatcher</servlet-name>
21+
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
22+
<init-param>
23+
<param-name>contextConfigLocation</param-name>
24+
<param-value>classpath*:springWebContext.xml</param-value>
25+
</init-param>
26+
<load-on-startup>1</load-on-startup>
27+
</servlet>
28+
<servlet-mapping>
29+
<servlet-name>spring-mvc-dispatcher</servlet-name>
30+
<url-pattern>/</url-pattern>
31+
</servlet-mapping>
32+
</web-app>
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<!DOCTYPE html>
2+
3+
<html>
4+
<head>
5+
<script type="text/javascript">
6+
if (navigator.geolocation) {
7+
navigator.geolocation.getCurrentPosition(capturePosition);
8+
}
9+
else {
10+
capturePosition();
11+
}
12+
13+
function capturePosition(position) {
14+
if (position && position.coords) {
15+
window.location = "/location?latitude=" + position.coords.latitude + "&longitude=" + position.coords.longitude;
16+
}
17+
else {
18+
window.location = "/location";
19+
}
20+
}
21+
</script>
22+
</head>
23+
</html>
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<!DOCTYPE html>
2+
3+
<html>
4+
<head>
5+
<title>Welcome!</title>
6+
</head>
7+
<body>
8+
<table>
9+
<tbody>
10+
<tr>
11+
<th valign="top">Latitude:</th>
12+
<td valign="top">${latitude}</d>
13+
</tr>
14+
<tr>
15+
<th valign="top">Longitude:</th>
16+
<td valign="top">${longitude}</d>
17+
</tr>
18+
</tbody>
19+
</table>
20+
</body>
21+
</html>

0 commit comments

Comments
 (0)