I have web app that was running fine on my local server the other day, behaving as it should but now something weird is happening and as far as i'm aware i haven't made any changes. When i choose to run the app on the local server the page will display fine. But when i click on a button, it's supposed to essentially send some data back and refresh the page with new information, which is what was happening before. Now however it is redirecting me to http://localhost/FirstSpringMVCProject/ instead of http://localhost:8080/FirstSpringMVCProject/ and i am getting an error. How to fix this? Below is the relevant code..
Controller
@Controller
public class HelloController {
@RequestMapping(value = "/", method = RequestMethod.GET)
public ModelAndView display() {
ModelAndView model = new ModelAndView("DisplayMatchup");
model.addObject("matchup", new Matchup());
return model;
}
@RequestMapping(value = "/", method = RequestMethod.POST)
public ModelAndView update(@ModelAttribute("team") String s) {
Util.updateParse(s);
ModelAndView model = new ModelAndView("DisplayMatchup");
model.addObject("matchup", new Matchup());
return model;
}
}
Spring servlet dispatcher
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc.xsd">
<context:component-scan base-package="com.gontuseries.hellocontroller" />
<mvc:annotation-driven/>
<bean id="viewResolver"
class="org.springframework.web.servlet.view.InternalResourceViewResolver" >
<property name="prefix">
<value>/WEB-INF/</value>
</property>
<property name="suffix">
<value>.jsp</value>
</property>
</bean>
</beans>
web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app id="WebApp_ID" version="3.0"
xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd">
<display-name>Web projects</display-name>
<servlet>
<servlet-name>spring-dispatcher</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
</servlet>
<welcome-file-list>
<welcome-file>DisplayMatchup.jsp</welcome-file>
</welcome-file-list>
<servlet-mapping>
<servlet-name>spring-dispatcher</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
</web-app>
View (DisplayMatchup.jsp)
<%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@taglib uri="http://www.springframework.org/tags/form" prefix="form"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/sql" prefix="sql"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<style>
ol {
padding: 12px;
background-color: #eee;
display: inline-block;
list-style-type: none;
text-align: center;
}
body {
font-family: Courier;
text-align: center;
}
button {
background-color: #4CAF50;
border: none;
color: white;
padding: 12px 25px;
text-align: center;
font-size: 18px;
font-family: Courier;
white-space: normal;
}
</style>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Basketball Player Rater</title>
</head>
<h2>Basketball Player Rater</h2>
<body>
<sql:setDataSource var="snapshot" driver="com.mysql.jdbc.Driver"
url="jdbc:mysql://results.cae10gzzpyrn.us-west-2.rds.amazonaws.com:3306/results"
user="user" password="pass"/>
<sql:query dataSource="${snapshot}" var="result">
SELECT * FROM records ORDER BY wins DESC;
</sql:query>
<ol>
<h2>Team 1</h2>
<form:form method="post" action="http://localhost/FirstSpringMVCProject/" modelAttribute="team">
<button type="submit" name="team" value="${matchup.teams[0]}${matchup.teams[1]}"/>${matchup.teams[0]}</button>
</form:form>
</ol>
<ol>
<h2>Team 2</h2>
<form:form method="post" action="http://localhost/FirstSpringMVCProject/" modelAttribute="team">
<button type="submit" name="team" value="${matchup.teams[1]}${matchup.teams[0]}"/>${matchup.teams[1]}</button>
</form:form>
</ol>
<h3>Results:</h3>
<c:forEach var="row" items="${result.rows}">
<c:out value="${row.player}"/> --- <c:out value="${row.winrate}"/>
</br>
</c:forEach>
</body>
</html>
Thanks, also if there is a better way to do what i'm trying to do then i'm open to suggestion.