-
Dec 24th, 2010, 09:56 PM
#1
Getting 404 Errors all the time
Hi all,
I tried configuring Spring annotated controller and no matter what I do, I keep getting 404 errors.
Heres my 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>AK-App</display-name>
<servlet>
<servlet-name>dispatcher</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherSe rvlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>dispatcher</servlet-name>
<url-pattern>*.htm</url-pattern>
</servlet-mapping>
<welcome-file-list>
<welcome-file>redirect.jsp</welcome-file>
</welcome-file-list>
</web-app>
Heres the dispatcher-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
="http://www.springframework.org/schema/p"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schem...-beans-3.0.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd">
<bean class="org.springframework.web.servlet.mvc.annotat ion.DefaultAnnotationHandlerMapping" />
<bean class="org.springframework.web.servlet.mvc.annotat ion.AnnotationMethodHandlerAdapter" />
<context:component-scan base-package="com.ak.akapp" />
<bean id="viewResolver"
class="org.springframework.web.servlet.view.Intern alResourceViewResolver">
<property name="prefix">
<value>/WEB-INF/jsp/</value>
</property>
<property name="suffix">
<value>.jsp</value>
</property>
</bean>
<bean id="propertyConfigurer"
class="org.springframework.beans.factory.config.Pr opertyPlaceholderConfigurer"
p:location="/WEB-INF/jdbc.properties" />
<bean id="dataSource" name="loginappdatasource"
class="org.springframework.jdbc.datasource.DriverM anagerDataSource"
p:driverClassName="${jdbc.driverClassName}"
p:url="${jdbc.url}"
p:username="${jdbc.username}"
p
assword="${jdbc.password}" />
</beans>
Heres my controller :
/**
*
*/
package com.ak.akapp;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMap ping;
import org.springframework.web.servlet.ModelAndView;
/**
* @author Anoop.Kammaran
*
*/
@Controller
@RequestMapping("/welcome/*")
public class HelloWorldController{
/* (non-Javadoc)
* @see org.springframework.web.servlet.mvc.AbstractContro ller#handleRequestInternal(javax.servlet.http.Http ServletRequest, javax.servlet.http.HttpServletResponse)
*/
@RequestMapping("/welcome.htm")
protected ModelAndView handleRequestInternal(HttpServletRequest arg0,
HttpServletResponse arg1) throws Exception {
return new ModelAndView("home","user", "Welcome: by Anoop");
}
@RequestMapping("/notwelcome.htm")
protected ModelAndView handleRequest(HttpServletRequest arg0,
HttpServletResponse arg1) throws Exception {
return new ModelAndView("home","user", "Not Welcome: by Anoop");
}
}
Heres the redirect.jsp that I use to execute the app :
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<% response.sendRedirect("/welcome/notwelcome.htm"); %>
--------------------------------------------------------------------
Can anyone tell me what I'm missing here? Thanks a lot in advance.
-
Dec 24th, 2010, 10:11 PM
#2
When I try manually defining beans in dispatcher-servlet, it says that it cannot map to a handler since there already exists a handler with the same mapping.
-
Dec 24th, 2010, 10:17 PM
#3
I do have one more controller :
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package com.ak.akapp.controller;
import com.ak.akapp.service.LoginService;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autow ired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMap ping;
import org.springframework.web.bind.annotation.RequestMet hod;
import org.springframework.web.servlet.ModelAndView;
/**
*
* @author Anoop.Kammaran
*/
@Controller
@RequestMapping("/login/*")
public class LoginController{
@Autowired
LoginService loginservice;
@RequestMapping(value="/submit.htm", method=RequestMethod.GET)
public ModelAndView handleRequestInternal(HttpServletRequest hsreq, HttpServletResponse hsres) throws Exception {
String user=hsreq.getParameter("user");
String passwd=hsreq.getParameter("passwd");
if(user!=null&&passwd!=null&&loginservice.isLoginV alid(user, passwd)){
return new ModelAndView("home", "user", user);
}
return new ModelAndView("error");
}
}
The requests to this controller are given from my index.jsp :
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!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=UTF-8">
<title>AK-App | Welcome</title>
</head>
<body>
<h1>Welcome to AK-App!</h1>
Please login ... <br/>
<form action="/login/submit.htm" method=GET>
<table>
<tr>
<td>
Enter UserName :
</td>
<td>
<input type="text" id="user" name="user"/>
</td>
</tr>
<tr>
<td>
Enter PassWord :
</td>
<td>
<input type="password" id="passwd" name="passwd"/>
</td>
</tr>
<tr>
<td>
<input type="submit" id="loginsubmit" name="Login" value="Login" />
</td>
<td>
<input type="reset" id="loginreset" name="Reset" value="Clear" />
</td>
</tr>
</table>
</form>
</body>
</html>
The problem is that I am unable to get the mappings work. I keep getting 404. I use Weblogic 11gR1 here.
-
Dec 24th, 2010, 10:25 PM
#4
Heres what I see at the console of weblogic :
Dec 25, 2010 9:51:29 AM org.springframework.context.support.AbstractApplic ationContext doClose
INFO: Closing WebApplicationContext for namespace 'dispatcher-servlet': startup date [Sat Dec 25 09:51:09 IST 2010]; root of context hierarchy
Dec 25, 2010 9:51:29 AM org.springframework.beans.factory.support.DefaultS ingletonBeanRegistry destroySingletons
INFO: Destroying singletons in org.springframework.beans.factory.support.DefaultL istableBeanFactory@81739c: defining beans [org.springframework.web.servlet.mvc.annotation.Def aultAnnotationHandlerMapping#0,org.springframework .web.servlet.mvc.annotation.AnnotationMethodHandle rAdapter#0,loginController,loginDaoImpl,helloWorld Controller,loginServiceImpl,org.springframework.co ntext.annotation.internalConfigurationAnnotationPr ocessor,org.springframework.context.annotation.int ernalAutowiredAnnotationProcessor,org.springframew ork.context.annotation.internalRequiredAnnotationP rocessor,org.springframework.context.annotation.in ternalCommonAnnotationProcessor,org.springframewor k.context.annotation.internalPersistenceAnnotation Processor,viewResolver,urlMapping,propertyConfigur er,dataSource]; root of factory hierarchy
Dec 25, 2010 9:51:32 AM org.springframework.web.servlet.FrameworkServlet initServletBean
INFO: FrameworkServlet 'dispatcher': initialization started
Dec 25, 2010 9:51:32 AM org.springframework.context.support.AbstractApplic ationContext prepareRefresh
INFO: Refreshing WebApplicationContext for namespace 'dispatcher-servlet': startup date [Sat Dec 25 09:51:32 IST 2010]; root of context hierarchy
Dec 25, 2010 9:51:33 AM org.springframework.beans.factory.xml.XmlBeanDefin itionReader loadBeanDefinitions
INFO: Loading XML bean definitions from ServletContext resource [/WEB-INF/dispatcher-servlet.xml]
Dec 25, 2010 9:51:33 AM org.springframework.core.io.support.PropertiesLoad erSupport loadProperties
INFO: Loading properties file from ServletContext resource [/WEB-INF/jdbc.properties]
Dec 25, 2010 9:51:33 AM org.springframework.beans.factory.support.DefaultL istableBeanFactory preInstantiateSingletons
INFO: Pre-instantiating singletons in org.springframework.beans.factory.support.DefaultL istableBeanFactory@1eb96fc: defining beans [org.springframework.web.servlet.mvc.annotation.Def aultAnnotationHandlerMapping#0,org.springframework .web.servlet.mvc.annotation.AnnotationMethodHandle rAdapter#0,loginController,loginDaoImpl,helloWorld Controller,loginServiceImpl,org.springframework.co ntext.annotation.internalConfigurationAnnotationPr ocessor,org.springframework.context.annotation.int ernalAutowiredAnnotationProcessor,org.springframew ork.context.annotation.internalRequiredAnnotationP rocessor,org.springframework.context.annotation.in ternalCommonAnnotationProcessor,org.springframewor k.context.annotation.internalPersistenceAnnotation Processor,viewResolver,urlMapping,propertyConfigur er,dataSource]; root of factory hierarchy
Dec 25, 2010 9:51:33 AM org.springframework.web.servlet.handler.AbstractUr lHandlerMapping registerHandler
INFO: Mapped URL path [/login/submit.htm] onto handler 'loginController'
Dec 25, 2010 9:51:33 AM org.springframework.web.servlet.handler.AbstractUr lHandlerMapping registerHandler
INFO: Mapped URL path [/welcome/notwelcome.htm] onto handler 'helloWorldController'
Dec 25, 2010 9:51:33 AM org.springframework.web.servlet.handler.AbstractUr lHandlerMapping registerHandler
INFO: Mapped URL path [/welcome/welcome.htm] onto handler 'helloWorldController'
Dec 25, 2010 9:51:33 AM org.springframework.web.servlet.handler.AbstractUr lHandlerMapping registerHandler
INFO: Mapped URL path [/loginController] onto handler 'loginController'
Dec 25, 2010 9:51:33 AM org.springframework.web.servlet.handler.AbstractUr lHandlerMapping registerHandler
INFO: Mapped URL path [/helloWorldController] onto handler 'helloWorldController'
Dec 25, 2010 9:51:33 AM org.springframework.jdbc.datasource.DriverManagerD ataSource setDriverClassName
INFO: Loaded JDBC driver: oracle.jdbc.xa.client.OracleXADataSource
Dec 25, 2010 9:51:34 AM org.springframework.web.servlet.FrameworkServlet initServletBean
INFO: FrameworkServlet 'dispatcher': initialization completed in 1227 ms
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules