Vote count:
0
I am new to Spring MVC and I am converting my standard Web Java project. I am having a problem making the project call a controller by default instead of a JSP page. In the web project before every request was handled by a controller and this doesn't seem to be the case with Spring could anyone advise?
I am using Netbeans and my code so far is below:
web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://ift.tt/19L2NlC"
xmlns:xsi="http://ift.tt/ra1lAU"
xsi:schemaLocation="http://ift.tt/19L2NlC http://ift.tt/1drxgYl"
version="3.1">
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/dispatcher-servlet.xml</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<servlet>
<servlet-name>dispatcher</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<load-on-startup>2</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>dispatcher</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
<session-config>
<session-timeout>
30
</session-timeout>
</session-config>
<welcome-file-list>
<welcome-file>/login</welcome-file>
</welcome-file-list>
Dispatcher Servlet
<?xml version='1.0' encoding='UTF-8' ?>
<beans xmlns="http://ift.tt/GArMu6"
xmlns:xsi="http://ift.tt/ra1lAU"
xmlns:mvc="http://ift.tt/1bHqwjR"
xmlns:context="http://ift.tt/GArMu7"
xsi:schemaLocation="http://ift.tt/GArMu6
http://ift.tt/1cnl1uo
http://ift.tt/GArMu7
http://ift.tt/1ldEMZY
http://ift.tt/1bHqwjR
http://ift.tt/1kF4x7W">
<context:component-scan base-package="com.danny" />
<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>
<mvc:resources mapping="/styles/**" location="/styles/" />
<mvc:annotation-driven />
LoginController
package com.spring.InternetJavaSpring.Controllers;
import com.spring.InternetJavaSpring.BusinessLogic.UserBusLog;
import static com.spring.InternetJavaSpring.BusinessLogic.UserBusLog.currentUser;
import com.spring.InternetJavaSpring.Model.Login;
import java.util.Map;
import javax.validation.Valid;
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;
@Controller
@RequestMapping(value="login")
public class LoginCont {
@RequestMapping(method = RequestMethod.GET)
public String login(Map<String, Object>model) {
Login user = new Login();
model.put("loginForm", user);
return "login";
}
@RequestMapping(method = RequestMethod.POST)
public String loginUser(@Valid @ModelAttribute("loginForm")
Login xLogin, BindingResult xResult, Map<String, Object>model) {
if(xResult.hasErrors()){
return "login";
}
UserBusLog ULogic = new UserBusLog();
ULogic.Login(xLogin);
model.put("fname", currentUser.getFName());
model.put("lname", currentUser.getLName());
return "home";
}
Any help would be a appreciated as I have spent two days on this and have got no where. Many thanks
asked 21 secs ago
Aucun commentaire:
Enregistrer un commentaire