Spring Hibernate integration with maven and mysql - spring

I need to have a project with spring hibernate and mysql, the homepage works fine (it even gets data out from mysql and displays it) but when i click the add/edit or delete button i get a 404 error with the description The request sent by the client was syntactically incorrect.
My student Controller.java
package com.joseph.controller;
import java.util.Map;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import com.joseph.model.Student;
import com.joseph.service.StudentService;
#Controller
public class StudentController {
#Autowired
private StudentService studentService;
#RequestMapping("/index")
public String setupForm(Map<String, Object> map){
Student student = new Student();
map.put("student", student);
map.put("studentList", studentService.getAllStudent());
return "student";
}
#RequestMapping(value="/student.do", method=RequestMethod.POST)
public String doActions(#ModelAttribute Student student, BindingResult result, #RequestParam String action, Map<String, Object> map){
// System.out.println("inside doAction");
Student studentResult = new Student();
// System.out.println("after student object");
switch(action.toLowerCase()){//only in Java7 you can put String in switch
case "add":
studentService.add(student);
studentResult = student;
System.out.println("Inside case action value is - add");
break;
case "edit":
studentService.edit(student);
studentResult = student;
System.out.println("Inside case action value is - edit");
break;
case "delete":
studentService.delete(student.getStudentId());
studentResult = new Student();
System.out.println("Inside case action value is - delete");
break;
case "search":
Student searchedStudent = studentService.getStudent(student.getStudentId());
studentResult = searchedStudent!=null ? searchedStudent : new Student();
System.out.println("Inside case action value is - search");
break;
}
System.out.println("after switch");
map.put("student", studentResult);
map.put("studentList", studentService.getAllStudent());
return "student";
}}
My web.xml file is
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web- app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" id="WebApp_ID" version="3.0">
<display-name>CRUDWebAppMavenized</display-name>
<context-param>
<param-name>log4jConfigLocation</param-name>
<param-value>classpath:log4j.xml</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.util.Log4jConfigListener</listener-class>
</listener>
<servlet>
<servlet-name>spring</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>spring</servlet-name>
<url-pattern>*.htm</url-pattern>
</servlet-mapping>
<servlet>
<servlet-name>spring1</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>spring1</servlet-name>
<url-pattern>*.do</url-pattern>
</servlet-mapping>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
<welcome-file>index.htm</welcome-file>
<welcome-file>index.jsp</welcome-file>
<welcome-file>default.html</welcome-file>
<welcome-file>default.htm</welcome-file>
<welcome-file>default.jsp</welcome-file>
My spring servlet.xml file
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:jee="http://www.springframework.org/schema/jee" xmlns:lang="http://www.springframework.org/schema/lang"
xmlns:p="http://www.springframework.org/schema/p" xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:util="http://www.springframework.org/schema/util"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee.xsd
http://www.springframework.org/schema/lang http://www.springframework.org/schema/lang/spring-lang.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util.xsd">
<context:annotation-config />
<context:component-scan base-package="com.joseph" />
<bean id="propertyConfigurer"
class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"
p:location="/WEB-INF/jdbc.properties" />
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource"
destroy-method="close" p:driverClassName="${jdbc.driverClassName}"
p:url="${jdbc.databaseurl}" p:username="${jdbc.username}" p:password="${jdbc.password}" />
<bean id="sessionFactory"
class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="dataSource" ref="dataSource" />
<property name="configLocation">
<value>classpath:hibernate.cfg.xml</value>
</property>
<property name="configurationClass">
<value>org.hibernate.cfg.AnnotationConfiguration</value>
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">${jdbc.dialect}</prop>
<prop key="hibernate.show_sql">true</prop>
</props>
</property>
</bean>
<bean id="viewResolver" class="org.springframework.web.servlet.view.UrlBasedViewResolver">
<property name="viewClass" value="org.springframework.web.servlet.view.JstlView"/>
<property name="prefix" value="/WEB-INF/jsp/"/>
<property name="suffix" value=".jsp"/>
</bean>
<tx:annotation-driven />
<bean id="transactionManager"
class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory" />
</bean>
My spring1-servlet.xml file is
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:jee="http://www.springframework.org/schema/jee" xmlns:lang="http://www.springframework.org/schema/lang"
xmlns:p="http://www.springframework.org/schema/p" xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:util="http://www.springframework.org/schema/util"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee.xsd
http://www.springframework.org/schema/lang http://www.springframework.org/schema/lang/spring-lang.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util.xsd">
<context:annotation-config />
<context:component-scan base-package="com.joseph" />
<bean id="propertyConfigurer"
class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"
p:location="/WEB-INF/jdbc.properties" />
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource"
destroy-method="close" p:driverClassName="${jdbc.driverClassName}"
p:url="${jdbc.databaseurl}" p:username="${jdbc.username}" p:password="${jdbc.password}" />
<bean id="sessionFactory"
class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="dataSource" ref="dataSource" />
<property name="configLocation">
<value>classpath:hibernate.cfg.xml</value>
</property>
<property name="configurationClass">
<value>org.hibernate.cfg.AnnotationConfiguration</value>
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">${jdbc.dialect}</prop>
<prop key="hibernate.show_sql">true</prop>
</props>
</property>
</bean>
<bean id="viewResolver" class="org.springframework.web.servlet.view.UrlBasedViewResolver">
<property name="viewClass" value="org.springframework.web.servlet.view.JstlView"/>
<property name="prefix" value="/WEB-INF/jsp/"/>
<property name="suffix" value=".jsp"/>
</bean>
<tx:annotation-driven />
<bean id="transactionManager"
class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory" />
</bean>
My student.jsp is
<%# page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<%# include file="/WEB-INF/jsp/includes.jsp"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Student Management</title>
</head>
<body>
<h1>Students Data</h1>
<form:form action="student.do" method="POST" commandName="student">
<table>
<tr>
<td>Student ID</td>
<td><form:input path="studentId" /></td>
</tr>
<tr>
<td>First name</td>
<td><form:input path="firstname" /></td>
</tr>
<tr>
<td>Last name</td>
<td><form:input path="lastname" /></td>
</tr>
<tr>
<td>Year Level</td>
<td><form:input path="yearLevel" /></td>
</tr>
<tr>
<td colspan="2">
<input type="submit" name="action1" value="Add" />
<input type="submit" name="action2" value="Edit" />
<input type="submit" name="action3" value="Delete" />
<input type="submit" name="action4" value="Search" />
</td>
</tr>
</table>
</form:form>
<br>
<table border="1">
<th>ID</th>
<th>First name</th>
<th>Last name</th>
<th>Year level</th>
<c:forEach items="${studentList}" var="student">
<tr>
<td>${student.studentId}</td>
<td>${student.firstname}</td>
<td>${student.lastname}</td>
<td>${student.yearLevel}</td>
</tr>
</c:forEach >
</table>
</body>
</html>
Any help with this guys ?! I mean its able to connect to the database perectly fine i have no clue why the buttons are not working

I see following two problems:
First Issue:
In your controller, you use
#RequestMapping(value="/student.do", method=RequestMethod.POST)
but in your form you use
<form:form action="student.do" method="POST" commandName="student">
Shouldn't your form also use /student.do? Only reason I suspect this is because you have indicated that you get 404 (Page not found) error on trying to add/update.
Second Issue:
You use four submit buttons each with its own name
<input type="submit" name="action1" value="Add" />
<input type="submit" name="action2" value="Edit" />
<input type="submit" name="action3" value="Delete" />
<input type="submit" name="action4" value="Search" />
but, your controller method's #RequestParam assumes that you will get the value in one param.
public String doActions(#ModelAttribute Student student,
BindingResult result,
#RequestParam String action, //***THIS IS WRONG****
Map<String, Object> map){
First you should change it have a name:
#RequestParam("action") String action,
and, second add a hidden field (<input type="hidden" name="action" />) to carry the value of action to server and make sure that you update its value to "Add", "Edit", "Delete" or "Search" using Java Script by attaching on-click handlers to four action buttons.
Third Possible Cause of Concern:
Try to get rid of second dispatcher servlet, and use only one if possible. So, make the default one handle *.do as some people have faced issues when using two dispatcher servlet. I am sure it can be made to work but its difficult to pinpoint the error remotely using SO.
<servlet>
<servlet-name>spring</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>spring</servlet-name>
<url-pattern>*.do</url-pattern>
</servlet-mapping>
and, have all your #RequestMapping use .do, eg: index.do and student.do
This answer is based on what I can make out from the question.

Related

HTTP Status 404 - /FitnessTracker/delete/1

I'm working on Spring MVC + Hibernate + JSP example. In this example I've developed below screen and delete button which I want to delete the populated record.
When I'm clicking on delete link, its says HTTP Status 404 - /FitnessTracker/delete/1. I am really not understanding what is wrong here.
MinutesController.java
#Controller
public class MinutesController {
#Autowired
private ExerciseService exerciseService;
#RequestMapping(value = "/addMinutes", method = RequestMethod.GET)
public String getMinutes(#ModelAttribute ("exercise") Exercise exercise, ModelMap model) {
List<Exercise> exercises = exerciseService.findAll();
model.addAttribute("exercises", exercises);
return "addMinutes";
}
#RequestMapping(value = "/addMinutes", method = RequestMethod.POST)
public String addMinutes(#Valid #ModelAttribute ("exercise") Exercise exercise, BindingResult result, ModelMap model ) {
// check if there are any errors
if(result.hasErrors()) {
return "addMinutes";
}
// save the new Exercise
exerciseService.save(exercise);
// return all saved exercises
List<Exercise> exercises = exerciseService.findAll();
model.addAttribute("exercises", exercises);
return "addMinutes";
}
#RequestMapping(value = "/activities", method = RequestMethod.GET)
public #ResponseBody List<Activity> findAllActivities() {
return exerciseService.findAllActivities();
}
#RequestMapping(value = "/delete/{exerciseId}",method = RequestMethod.GET)
public String deleteActivity(#PathVariable("exerciseId") Long exerciseId) {
exerciseService.deleteExercise(exerciseId);
return "redirect:/activities";
}
}
addMinutes.jsp
<form:form commandName="exercise">
<form:errors path="*" cssClass="errorblock" element="div" />
<h4>View All Exercises</h4>
<table align="left" border="1" cellpadding="10">
<tr>
<th><b>Minutes</b></th>
<th><b>Activity</b></th>
<th><b>Delete</b></th>
</tr>
<c:forEach var="exercise" items="${exercises}">
<tr>
<td>${exercise.minutes}</td>
<td>${exercise.activity}</td>
<td><a href="<c:url value='/delete/${exercise.exerciseId}' />" >Delete</a></td>
</tr>
</c:forEach>
</table>
</form:form>
web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5" 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_2_5.xsd">
<servlet>
<servlet-name>fitTrackerServlet</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:spring/servlet-config.xml</param-value>
</init-param>
</servlet>
<servlet-mapping>
<servlet-name>fitTrackerServlet</servlet-name>
<url-pattern>*.html</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>fitTrackerServlet</servlet-name>
<url-pattern>/pdfs/**</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>fitTrackerServlet</servlet-name>
<url-pattern>/images/**</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>fitTrackerServlet</servlet-name>
<url-pattern>*.json</url-pattern>
</servlet-mapping>
<display-name>Archetype Created Web Application</display-name>
</web-app>
servlet-config.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xmlns:p="http://www.springframework.org/schema/p"
xmlns:jpa="http://www.springframework.org/schema/data/jpa"
xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd
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/data/jpa http://www.springframework.org/schema/data/jpa/spring-jpa.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd">
<import resource="classpath:spring/database.xml"/>
<mvc:annotation-driven/>
<context:annotation-config />
<context:component-scan base-package="com.pluralsight"/>
<!-- For Static Resources -->
<mvc:resources location="assets" mapping="/assets/**"/>
<mvc:resources location="pdfs" mapping="/pdfs/**"/>
<bean class="org.springframework.web.servlet.view.ContentNegotiatingViewResolver">
<property name="order" value="1" />
<property name="contentNegotiationManager">
<bean class="org.springframework.web.accept.ContentNegotiationManager">
<constructor-arg>
<bean class="org.springframework.web.accept.PathExtensionContentNegotiationStrategy">
<constructor-arg>
<map>
<entry key="json" value="application/json" />
<entry key="xml" value="application/xml" />
</map>
</constructor-arg>
</bean>
</constructor-arg>
</bean>
</property>
<property name="defaultViews">
<list>
<bean class="org.springframework.web.servlet.view.json.MappingJackson2JsonView" />
<bean class="org.springframework.web.servlet.view.xml.MarshallingView">
<constructor-arg>
<bean class="org.springframework.oxm.xstream.XStreamMarshaller">
<property name="autodetectAnnotations" value="true" />
</bean>
</constructor-arg>
</bean>
</list>
</property>
</bean>
<mvc:interceptors>
<bean class="org.springframework.web.servlet.i18n.LocaleChangeInterceptor" p:paramName="language"/>
</mvc:interceptors>
<bean id="localeResolver" class="org.springframework.web.servlet.i18n.SessionLocaleResolver" p:defaultLocale="en"/>
<bean id="messageSource"
class="org.springframework.context.support.ResourceBundleMessageSource"
p:basename="messages"></bean>
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver"
p:prefix="/WEB-INF/jsp/"
p:suffix=".jsp" p:order="2"/>
<bean class="org.springframework.web.servlet.view.BeanNameViewResolver" p:order="0"/>
</beans>

Neither BindingResult nor plain target object for bean name 'register_form' available as request attribute Error

Just needed a small help regarding Spring form functionality using spring. I am new to Spring form handling. I have created a register page functionality in which a user just enters his registration details and they are inserted into database. However after all set up code is written i am getting an error 'Neither BindingResult nor plain target object for bean name 'register_form' available as request attribute'. I have checked several questions here and tried all things. I found my code is fine but still getting this error.
Please see my below files :
Web.xml :
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5">
<display-name>TestFactoryPat</display-name>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
<welcome-file>index.htm</welcome-file>
<welcome-file>index.jsp</welcome-file>
<welcome-file>default.html</welcome-file>
<welcome-file>default.htm</welcome-file>
<welcome-file>default.jsp</welcome-file>
</welcome-file-list>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/Application-context.xml, /WEB-INF/mvc-dispatcher-servlet.xml</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<servlet>
<servlet-name>mvc-dispatcher</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/mvc-dispatcher-servlet.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>mvc-dispatcher</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
</web-app>
Application-context.xml:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:p="http://www.springframework.org/schema/p"
xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-2.5.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-2.5.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-2.5.xsd">
<!-- "http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">-->
<bean id="transactionManager"
class="org.springframework.orm.hibernate3.HibernateTransactionManager"
p:sessionFactory-ref="sessionFactoryBean" />
<tx:annotation-driven/>
<bean id="dataSourceBean" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName" value="com.mysql.jdbc.Driver"></property>
<property name="url" value="jdbc:mysql://localhost/springmvc"></property>
<property name="username" value="root"></property>
<property name="password" value="root"></property>
</bean>
<bean id="sessionFactoryBean" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="dataSource" ref="dataSourceBean"></property>
<!--<property name="mappingResources">
<value>com.lnt.Pojo/Login.hbm.xml</value>
</property>-->
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">org.hibernate.dialect.MySQL5Dialect</prop>
<prop key="hibernate.show_sql">true</prop>
</props>
</property>
</bean>
<bean id="hibernateTemplateBean" class="org.springframework.orm.hibernate3.HibernateTemplate">
<property name="sessionFactory" ref="sessionFactoryBean"></property>
</bean>
<!-- <bean id="AuthenticateServiceBean" class="com.lnt.services.AuthenticateServices">
<property name="hibernateTemplate" ref="hibernateTemplateBean"></property>
</bean> -->
</beans>
MVC-Dispatcher servlet.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:security="http://www.springframework.org/schema/security"
xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd
http://www.springframework.org/schema/security http://www.springframework.org/schema/security/spring-security-3.0.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<context:component-scan base-package="com.karan.TestFactory.Controller"></context:component-scan>
<bean id = "viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix">
<value>/</value>
</property>
<property name="suffix">
<value>.jsp</value>
</property>
</bean>
</beans>
My controller class for registration :
#Controller
public class RegisterController {
#Autowired
private BaseServices baseimpl;
#RequestMapping(value="/submitRegistration", method = RequestMethod.GET)
public String adduser(Registration_info register_form)
{
baseimpl.saveorupdate(register_form);
return null;
}
}
Registeruser.jsp page :
<%# page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<%#taglib uri="http://www.springframework.org/security/tags"
prefix="sec"%>
<%#taglib uri="http://www.springframework.org/tags" prefix="spring"%>
<%#taglib uri="http://www.springframework.org/tags/form" prefix="form"%>
<%#taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn"%>
<%#taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%#taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Test Registration</title>
</head>
<body>
<h5> Registration Page</h5>
<form:form id="RegisterForm" action="/submitRegistration" method="GET" modelAttribute="register_form">
<table>
<tr>
<td>FirstName</td>
<td>
<td>
<form:input path="register_form.firstName" size="30" />
</td>
<tr>
<td>LastName</td>
<td></td>
</tr>
<td>
<form:input path="register_form.LasttName" size="30" />
</td>
<tr>
<td>Email Address</td>
<td></td>
</tr>
<td>
<form:input path="register_form.EmailAddress" size="30" />
</td>
<tr>
<td>Address</td>
<td></td>
</tr>
<td>
<form:input path="register_form.Address" size="30" />
</td>
<tr>
<td>Phone</td>
<td></td>
</tr>
<td>
<form:input path="register_form.Phone" size="30" />
</td>
<tr>
<td>
<input type="submit" value="Submit Registration">
</td>
</tr>
</table>
</form:form>
</body>
</html>
Please let me know if this issue can be resolved i have checked all my jar files also.
Although it won't fix the problem, you form submission method should be POST instead of GET.
With that in mind make the following changes to your code:
<form:form id = "RegisterForm" action = "/submitRegistration" method = "POST" commandName= "register_form">
#RequestMapping(value="/submitRegistration", method = RequestMethod.POST)
public String adduser(#ModelAttribute("register_form") Registration_info register_form)

Type mismatch when I enter string for Int in one of the form parameter when I submit form in spring 3

I have a jsp form as following :
<form:form method="POST" commandName="command" action="RouteGradesGoals.html" >
<tr>
<td class="style4" colspan="2">
Goal</td>
<td colspan="2">
<form:input path="goal" type="text" id="goal" style="width:200px;" />
</td>
<td colspan="2">
<form:errors path="goal" cssClass="error" />
</td>
</tr>
<input type="submit" name="action" value="Delete" id="Button3"
class="submitButton" />
</form:form>
As you see there is only one parameter goal in the command object and it is of type int in the command object.
But when I submit the form I gets this error by passing string for int in the goal param:
{"detail":"An error has occured while processing the request: org.springframework.validation.BeanPropertyBindingResult: 1 errors\nField error in object 'command' on field 'goal': rejected value [sadfasd]; codes [typeMismatch.command.goal,typeMismatch.goal,typeMismatch.java.lang.Integer,typeMismatch]; arguments [org.springframework.context.support.DefaultMessageSourceResolvable: codes [command.goal,goal]; arguments []; default message [goal]]; default message [Failed to convert property value of type 'java.lang.String' to required type 'java.lang.Integer' for property 'goal'; nested exception is java.lang.NumberFormatException: For input string: \"sadfasd\"]"}
The controller has a simple method to process this form as given below:
#RequestMapping( value = "/RouteGradesGoals.html", method = RequestMethod.POST )
public String addInventoryGoal(#ModelAttribute( "command" ) InventoryGoal goal, HttpServletRequest request,
BindingResult result, SessionStatus status, ModelMap model, HttpSession session){
inventoryGoalValidator.validate(goal, result);
if (result.hasErrors()) {
return "RouteGradesGoals";
}
// do processing of the command object
return "RouteGradesGoals";
}
Command object is as follows :
public class InventoryGoal {
private Integer goal;
public Integer getGoal() {
return goal;
}
public void setGoal(Integer goal) {
this.goal = goal;
}
}
This is how I have added the message resolver in the context xml file :
<bean id="messageSource"
class="org.springframework.context.support.ReloadableResourceBundleMessageSource">
<property name="basename" value="classpath:messages" />
<property name="defaultEncoding" value="UTF-8"/>
</bean>
<bean id="localeChangeInterceptor"
class="org.springframework.web.servlet.i18n.LocaleChangeInterceptor">
<property name="paramName" value="lang" />
</bean>
<bean id="localeResolver"
class="org.springframework.web.servlet.i18n.CookieLocaleResolver">
<property name="defaultLocale" value="en"/>
</bean>
<bean id="handlerMapping"
class="org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping">
<property name="interceptors">
<ref bean="localeChangeInterceptor" />
</property>
</bean>
I have added these properties in the messages.properties
typeMismatch.command.goal=invalid goal1
typeMismatch.goal=invalid goal2
typeMismatch.java.lang.Integer=invalid goal2
typeMismatch=invalid goal3
web.xml :
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
version="2.5">
<display-name>Forerunner Webservice</display-name>
<context-param>
<param-name>contextClass</param-name>
<param-value>org.springframework.web.context.support.AnnotationConfigWebApplicationContext</param-value>
</context-param>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>com.ids.forerunner.web.configuration.WebConfig</param-value>
</context-param>
<context-param>
<param-name>spring.profiles.active</param-name>
<param-value>mysql</param-value>
</context-param>
<servlet>
<servlet-name>restService</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value></param-value>
</init-param>
<load-on-startup>2</load-on-startup>
</servlet>
<servlet>
<servlet-name>webapp</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>webapp</servlet-name>
<url-pattern>/webapp/*</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>restService</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
<filter>
<!-- The CORS filter with parameters -->
<filter-name>CORS</filter-name>
<filter-class>com.ids.cors.CORSFilter</filter-class>
<!-- Note: All parameters are options, if ommitted CORS Filter
will fall back to the respective default values.
-->
<init-param>
<param-name>cors.allowGenericHttpRequests</param-name>
<param-value>true</param-value>
</init-param>
<init-param>
<param-name>cors.allowOrigin</param-name>
<param-value>*</param-value>
</init-param>
<init-param>
<param-name>cors.supportedMethods</param-name>
<param-value>GET, HEAD, POST, OPTIONS</param-value>
</init-param>
<init-param>
<param-name>cors.supportedHeaders</param-name>
<param-value>Content-Type, X-Requested-With</param-value>
</init-param>
<init-param>
<param-name>cors.exposedHeaders</param-name>
<param-value>X-Test-1, X-Test-2</param-value>
</init-param>
<init-param>
<param-name>cors.supportsCredentials</param-name>
<param-value>true</param-value>
</init-param>
<init-param>
<param-name>cors.maxAge</param-name>
<param-value>3600</param-value>
</init-param>
</filter>
<filter-mapping>
<!-- CORS Filter mapping -->
<filter-name>CORS</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<filter>
<filter-name>APIProtectionFilter</filter-name>
<filter-class>com.ids.forerunner.filter.APIProtectionFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>APIProtectionFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
</welcome-file-list>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
</web-app>
in the WebConfig.java I am importing resources as given below:
#ImportResource({"classpath:/META-INF/spring/forerunner-service.xml","/WEB-INF/webapp-servlet.xml"})
webapp-servlet.xml :
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xmlns:util="http://www.springframework.org/schema/util"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc-3.1.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.0.xsd
http://www.springframework.org/schema/util
http://www.springframework.org/schema/util/spring-util-3.0.xsd">
<bean id="viewResolver"
class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix">
<value>/WEB-INF/jsp/</value>
</property>
<property name="suffix">
<value>.jsp</value>
</property>
</bean>
<context:component-scan base-package="com.ids.forerunner.webapp.controllers" />
<mvc:resources mapping="/css/**" location="/css/" />
<mvc:resources mapping="/images/**" location="/images/" />
<mvc:resources mapping="/js/**" location="/js/" />
<mvc:resources mapping="/forerunner_style.css" location="/forerunner_style.css" />
<mvc:interceptors>
<mvc:interceptor>
<mvc:mapping path="/**" />
<bean class="com.ids.forerunner.webapp.interceptor.ForerunnerRequestInterceptor" />
</mvc:interceptor>
</mvc:interceptors>
<bean id="messageSource" class=" org.springframework.context.support.ReloadableResourceBundleMessageSource">
<property name="basename" value="classpath:message-webapp-error" />
</bean>
<!-- <util:properties id="tophireProperties" location="classpath:tophire.properties" /> -->
</beans>
forerunner-service.xml:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:c="http://www.springframework.org/schema/c" xmlns:cache="http://www.springframework.org/schema/cache"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:jee="http://www.springframework.org/schema/jee" xmlns:lang="http://www.springframework.org/schema/lang"
xmlns:mvc="http://www.springframework.org/schema/mvc" xmlns:p="http://www.springframework.org/schema/p"
xmlns:task="http://www.springframework.org/schema/task" xmlns:util="http://www.springframework.org/schema/util"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.1.xsd
http://www.springframework.org/schema/cache http://www.springframework.org/schema/cache/spring-cache-3.1.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.1.xsd
http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-3.1.xsd
http://www.springframework.org/schema/lang http://www.springframework.org/schema/lang/spring-lang-3.1.xsd
http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.1.xsd
http://www.springframework.org/schema/task http://www.springframework.org/schema/task/spring-task-3.1.xsd
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util.xsd">
<!-- Enables automatic mapping of fund objects to and from JSON -->
<mvc:annotation-driven />
<import resource="classpath:/META-INF/spring/applicationContext.xml" />
<import resource="classpath:/META-INF/spring/applicationContext-jpa.xml" />
<bean id="contactFormValidator" class="com.ids.forerunner.webapp.validator.ContactFormValidator" />
<bean id="inventoryGoalValidator" class="com.ids.forerunner.webapp.validator.InventoryGoalValidator" />
<bean id="anchorAreaValidator" class="com.ids.forerunner.webapp.validator.AnchorAreaValidator" />
<bean class="com.ids.forerunner.util.ForerunnerInitializer"/>
<bean class="org.dozer.spring.DozerBeanMapperFactoryBean">
<property name="mappingFiles" value="classpath*:/dozer-bean-mappings.xml" />
</bean>
<!-- Setup spring to pull in #Controller, #RequestMapping, etc. Configuration
scans specified packages for classes configured as Spring managed beans and
automatically sets up objects annotated with #Controller, #Service etc. -->
<context:component-scan base-package="com.ids.forerunner.web" />
<bean
class="org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping"></bean>
<!-- Configures view for returning JSON to the client -->
<bean
class="org.springframework.web.servlet.view.json.MappingJacksonJsonView"
p:contentType="text/plain"></bean>
<!-- maps handler methods based on HTTP paths -->
<bean
class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter">
<property name="messageConverters">
<util:list id="beanList">
<ref bean="jsonMessageConverter" />
</util:list>
</property>
</bean>
<!-- Converts JSON to POJO and vice versa -->
<bean id="jsonMessageConverter"
class="org.springframework.http.converter.json.MappingJacksonHttpMessageConverter" />
<bean id="viewResolver"
class="org.springframework.web.servlet.view.InternalResourceViewResolver"
p:prefix="/WEB-INF/pages/" p:suffix=".jsp">
</bean>
<bean id="messageSource"
class="org.springframework.context.support.ReloadableResourceBundleMessageSource">
<property name="basename" value="classpath:messages" />
<property name="defaultEncoding" value="UTF-8"/>
</bean>
<bean id="localeChangeInterceptor"
class="org.springframework.web.servlet.i18n.LocaleChangeInterceptor">
<property name="paramName" value="lang" />
</bean>
<bean id="localeResolver"
class="org.springframework.web.servlet.i18n.CookieLocaleResolver">
<property name="defaultLocale" value="en"/>
</bean>
<bean id="handlerMapping"
class="org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping">
<property name="interceptors">
<ref bean="localeChangeInterceptor" />
</property>
</bean>
<bean id="taskList" class="com.forerunner.cronjobs.TaskList">
<property name="taskList">
<list>
<bean name="sessionTask" class="com.forerunner.cronjobs.SessionCronTask"></bean>
</list>
</property>
</bean>
<bean name="jobDetail" class="org.springframework.scheduling.quartz.JobDetailBean">
<property name="jobClass" value="com.forerunner.cronjobs.ForerunnerCronJob" />
<property name="jobDataAsMap">
<map>
<entry key="taskList" value-ref="taskList" />
</map>
</property>
</bean>
<bean id="cronTrigger" class="com.forerunner.cronjobs.ForerunnerTrigger">
<property name="jobDetail" ref="jobDetail" />
</bean>
<bean class="org.springframework.scheduling.quartz.SchedulerFactoryBean">
<property name="jobDetails">
<list>
<ref bean="jobDetail" />
</list>
</property>
<property name="triggers">
<list>
<ref bean="cronTrigger" />
</list>
</property>
</bean>
</beans>
In the message-webapp-error.properties I have properties as follows :
typeMismatch.command.goal=invalid goal1
typeMismatch.goal=invalid goal2
typeMismatch.java.lang.Integer=invalid goal2
typeMismatch=invalid goal3
Form is posted to this url http:///forerunner/webapp/RouteGradesGoals.html
Can someone please tell me how can I prevent such error and in such scenerios return a valid error message.
Configure a MessageSource and provide a message for one of the shown error codes
typeMismatch.command.goal
typeMismatch.goal
typeMismatch.java.lang.Integer
typeMismatch
Which provides messages from most specific to least specific.
<bean id="messageSource" class=" org.springframework.context.support.ReloadableResourceBundleMessageSource">
<property name="basename" value="classpath:messages" />
</bean>
This MessageSource will load a messages.properties (or locale specific one) from the root of the classpath. Add it and fill it accordingly
typeMismatch.command.goal=The goal needs to be a valid number.
typeMismatch.java.lang.Integer=The given input is not a valid number.
Now with this content for your case the first message will be shown, for other typeMismatch errors on Integer fields the second one will be shown.
For more information on a MessageSource see the reference guide and javadoc. More information on error code generation here.

Login page with Spring Security not working URL(http://localhost:8080/site/j_spring_security_check) goes to PAGE NOT FOUND

I am new to hippo and working on hippo cms site.
I am working on creating a login page with spring security. For this I created the following files and did the configuration for spring and spring security.
Here is my Login.jsp.
<%# taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<html>
<head>
<title>Login Page</title>
<style>
.errorblock {
color: #ff0000;
background-color: #ffEEEE;
border: 3px solid #ff0000;
padding: 8px;
margin: 16px;
}
</style>
</head>
<body onload='document.f.j_username.focus();'>
<h3>Login with Username and Password (Custom Page)</h3>
<c:if test="${not empty error}">
<div class="errorblock">
Your login attempt was not successful, try again.<br /> Caused :
${sessionScope["SPRING_SECURITY_LAST_EXCEPTION"].message}
</div>
</c:if>
<form name='f' action="/j_spring_security_check"
method='POST'>
<table>
<tr>
<td>User:</td>
<td><input type='text' name='j_username' value=''>
</td>
</tr>
<tr>
<td>Password:</td>
<td><input type='password' name='j_password' />
</td>
</tr>
<tr>
<td colspan='2'><input name="submit" type="submit"
value="submit" />
</td>
</tr>
<tr>
<td colspan='2'><input name="reset" type="reset" />
</td>
</tr>
</table>
</form>
</body>
</html>
The configuration files.
1) Web.xml configuration
<?xml version="1.0" encoding="UTF-8"?>
<web-app id="WebApp_ID" version="2.4"
xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee
http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
<display-name>Spring MVC Application</display-name>
<!-- Spring MVC -->
<servlet>
<servlet-name>mvc-dispatcher</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>mvc-dispatcher</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
<listener>
<listener class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>
/WEB-INF/mvc-dispatcher-servlet.xml,
/WEB-INF/spring-database.xml,
/WEB-INF/spring-security.xml
</param-value>
</context-param>
<!-- Spring Security -->
<filter>
<filter-name>springSecurityFilterChain</filter-name>
<filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
</filter>
<filter-mapping>
<filter-name>springSecurityFilterChain</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
</web-app>
2) mvc-dispatcher-servlet.xml
<?xml version="1.0" encoding="UTF-8"?>
<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"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.0.xsd">
<context:component-scan base-package="com.example.common.controller" />
<bean
class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix">
<value>/WEB-INF/pages/</value>
</property>
<property name="suffix">
<value>.jsp</value>
</property>
</bean>
<bean id="messageSource"
class="org.springframework.context.support.ResourceBundleMessageSource">
<property name="basenames">
<list>
<value>mymessages</value>
</list>
</property>
</bean>
</beans>
3) spring-database.xml
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd">
<bean id="dataSource"
class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName" value="com.mysql.jdbc.Driver" />
<property name="url" value="jdbc:mysql://localhost:3306/vnp_db" />
<property name="username" value="root" />
<property name="password" value="admin" />
</bean>
</beans>
4) spring-security.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans:beans xmlns="http://www.springframework.org/schema/security"
xmlns:beans="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/security
http://www.springframework.org/schema/security/spring-security-3.0.xsd">
<http auto-config="true">
<intercept-url pattern="/welcome*" access="ROLE_USER" />
<form-login login-page="/login" default-target-url="/welcome"
authentication-failure-url="/loginfailed" login-processing-url="/j_spring_security_check"/>
<logout logout-success-url="/logout" />
</http>
<authentication-manager>
<authentication-provider>
<jdbc-user-service data-source-ref="dataSource"
users-by-username-query="
select email,password, enabled
from users where email=?"
authorities-by-username-query="
select u.email, ur.authority from users u, authorities ur
where u.email = ur.email and u.email =? "
/>
</authentication-provider>
</authentication-manager>
</beans:beans>
And the controller file
This module also contains registration part using spring thar part is working fine . On the login page I fill the correct username and password and clicks "Login" button. The url goes to "http://testcebs.com:8080/site/j_spring_security_check" and redirects to PAGE NOT FOUND instead of success and fail.No authentication process initatied after clicking on "Login" button. I am not able to understand why it is not working. However the same code and configuration is working fine in eclipse as a spring application.
You've been answered here and here, please don't cross-post
The answers:
if the j_spring_security_check URL is not part of the HST driven then make sure you add it to you hst:hosts exclusions, because otherwise the HST thinks it needs to handle the URL.
and
You need to insert the​ SpringSecurityValve into your existing pipelines​ as well​.
​you can use the hippo-spring-sec​ plugin for a cleaner spring security integration; http://hst-springsec.forge.onehippo.org/

WARNING: No mapping found for HTTP request with URI [/XboxVoting/ownedGames] in DispatcherServlet with name 'spring'

I've looked through other answers on here as best I can, but nothing seems to exactly fit my issue/solve my problem. Essentially, I get the above error when I try and access ownedGames from my index.
I feel like I have the mapping done correctly, but obviously I don't. So here I'll post any files that seem like they may be relevant.
index.html (where I click links that give the errors)
<html>
<head>
<title>xbox voting</title>
</head>
<body>
Vote on Games! <br />
View the Games We Own!
</body>
</html>
web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
id="WebApp_ID" version="2.5">
<display-name>Spring3-Hibernate</display-name>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
<servlet>
<servlet-name>spring</servlet-name>
<servlet-class>
org.springframework.web.servlet.DispatcherServlet
</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>spring</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
</web-app>
spring-servlet.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:jee="http://www.springframework.org/schema/jee"
xmlns:lang="http://www.springframework.org/schema/lang"
xmlns:p="http://www.springframework.org/schema/p"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:util="http://www.springframework.org/schema/util"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee.xsd
http://www.springframework.org/schema/lang http://www.springframework.org/schema/lang/spring-lang.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util.xsd">
<context:annotation-config />
<context:component-scan base-package="net.nerdery.xboxvoting.controller" />
<bean id="jspViewResolver"
class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="viewClass"
value="org.springframework.web.servlet.view.JstlView" />
<property name="prefix" value="/WEB-INF/jsp/" />
<property name="suffix" value=".jsp" />
</bean>
<bean id="messageSource"
class="org.springframework.context.support.ReloadableResourceBundleMessageSource">
<property name="basename" value="classpath:messages" />
<property name="defaultEncoding" value="UTF-8" />
</bean>
<bean id="propertyConfigurer"
class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"
p:location="jdbc.properties" />
<bean id="dataSource"
class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close"
p:driverClassName="${jdbc.driverClassName}"
p:url="${jdbc.databaseurl}" p:username="${jdbc.username}"
p:password="${jdbc.password}" />
<bean id="sessionFactory"
class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="dataSource" ref="dataSource" />
<property name="configLocation">
<value>hibernate.cfg.xml</value>
</property>
<property name="configurationClass">
<value>org.hibernate.cfg.AnnotationConfiguration</value>
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">${jdbc.dialect}</prop>
<prop key="hibernate.show_sql">true</prop>
</props>
</property>
</bean>
<tx:annotation-driven />
<bean id="transactionManager"
class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory" />
</bean>
</beans>
GameController
package net.nerdery.xboxvoting.controller;
import java.util.Map;
import net.nerdery.xboxvoting.domain.Game;
import net.nerdery.xboxvoting.service.GameService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
#Controller
public class GameController {
#Autowired
private GameService gameService;
#RequestMapping("/XboxVoting/ownedGames")
public String listOwnedGames(Map<String, Object> map) {
map.put("game", new Game());
map.put("ownedGamesList", gameService.listOwnedGames());
return "game";
}
#RequestMapping("/wantedGames")
public String listWantedGames(Map<String, Object> map) {
map.put("game", new Game());
map.put("wantedGamesList", gameService.listOwnedGames());
return "game";
}
#RequestMapping(value = "/add", method = RequestMethod.POST)
public String addGame(#ModelAttribute("game")
Game game, BindingResult result) {
gameService.addGame(game);
return "redirect:/ownedGames";
}
}
I'm sure it's some silly syntax error I'm missing somewhere, but I'm new to Spring (just started today) and have hardly any idea what I'm doing. So thanks for any help!
you need change
<url-pattern>/</url-pattern>
to
<url-pattern>/*</url-pattern>
You are using absolute path in href so you should specify complete path there
or instead of that use relative path (append / in beginning of href) like
Vote on Games! <br />
View the Games We Own!
Also try adding method = RequestMethod.GET to your controller.
I am not sure about your URL structure.

Resources