我正在尝试从Spring mvc jdbc模板获取数据并以表格格式显示。但是总是出现404错误。
package com.sample.complaint.controller;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;
import com.sample.domain.TrackComplaints;
import com.sample.services.TrackComplaintsService;
@Controller
public class TrackComplaintsController {
@Autowired
ComplaintsService complaintservice;
@RequestMapping("/userList" )
public ModelAndView Complaints() {
List<Complaints> complaintlist = complaintservice.getComplaintsList();
return new ModelAndView("userList", "Complaints",
complaintlist);
}
}
我的ApplicationContect.xml //调度程序servlet
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:mvc="http://www.springframework.org/schema/mvc"
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
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd">
<mvc:default-servlet-handler />
<!-- telling container to take care of annotations stuff -->
<context:annotation-config />
<!-- declaring base package -->
<context:component-scan base-package="com.sample.*" />
<!-- adding view resolver to show jsp's on browser -->
<bean id="viewResolver"
class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/WEB-INF/jsp/" />
<property name="suffix" value=".jsp" />
</bean>
<!-- declare beans -->
<bean id="trackcomplainsdao" class="com.sample.dao.ComplaintsDaoImpl" />
<bean id="trackcomplaintservice" class="com.sample.services.ComplaintsSerImpl" />
<!-Datasource code is present--!>
</beans>
的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>SpringJDBCTemplate</display-name>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
<servlet>
<servlet-name>ApplicationContext</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>ApplicationContext</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
</web-app>
userList.jsp
%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<%@ taglib uri="http://www.springframework.org/tags/form" prefix="form"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<html>
<head>
<title>Complaint</title>
</head>
<body>
<center>
<b>Complaints </b>
<table border="1">
<tr>
<td class="heading">asd</td>
<td class="heading">Sasde</td>
<td class="heading">erte</td>
<td class="heading">gjg</td>
<td class="heading">Sghj</td>
<td class="heading">vbn</td>
<td class="heading">vbngh</td>
<td class="heading">gfh</td>
</tr>
<c:forEach var="complaints" items="${complaintsList}">
<tr>
<td>${complaints.asd}</td>
<td>${complaints.Sasde}</td>
<td>${complaints.erte}</td>
<td>${complaints.gjg}</td>
<td>${complaints.Sghj}</td>
<td>${complaints.vbn}</td>
<td>${complaints.vbngh}</td>
<td>${complaints.gfh}</td>>
</tr>
</c:forEach>
</table>
</center>
</body>
</html>
我不知道我是否错过了请求映射或其他东西。提前谢谢
控制台:
Sep 24, 2014 5:44:37 PM org.apache.catalina.core.AprLifecycleListener init
INFO: The APR based Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path: C:\Program Files\Java\jre7\bin;C:\windows\Sun\Java\bin;C:\windows\system32;C:\windows;C:/Program Files/Java/jre7/bin/client;C:/Program Files/Java/jre7/bin;C:/Program Files/Java/jre7/lib/i386;D:\oracle\TCSHYDISUSER\product\11.2.0\client_1\BIN;C:\OraHome_1\bin;C:\OraHome_1;C:\windows\system32;C:\windows;C:\windows\System32\Wbem;C:\windows\System32\WindowsPowerShell\v1.0\;;C:\Java IDE\eclipse-jee-kepler-R-win32\eclipse;;.
Sep 24, 2014 5:44:37 PM org.apache.tomcat.util.digester.SetPropertiesRule begin
WARNING: [SetPropertiesRule]{Server/Service/Engine/Host/Context} Setting property 'source' to 'org.eclipse.jst.jee.server:sample' did not find a matching property.
Sep 24, 2014 5:44:37 PM org.apache.coyote.AbstractProtocol init
INFO: Initializing ProtocolHandler ["http-bio-8080"]
Sep 24, 2014 5:44:37 PM org.apache.coyote.AbstractProtocol init
INFO: Initializing ProtocolHandler ["ajp-bio-8009"]
Sep 24, 2014 5:44:37 PM org.apache.catalina.startup.Catalina load
INFO: Initialization processed in 418 ms
Sep 24, 2014 5:44:37 PM org.apache.catalina.core.StandardService startInternal
INFO: Starting service Catalina
Sep 24, 2014 5:44:37 PM org.apache.catalina.core.StandardEngine startInternal
INFO: Starting Servlet Engine: Apache Tomcat/7.0.42
Sep 24, 2014 5:44:41 PM org.apache.catalina.core.ApplicationContext log
INFO: No Spring WebApplicationInitializer types detected on classpath
Sep 24, 2014 5:44:41 PM org.apache.catalina.core.ApplicationContext log
INFO: Initializing Spring FrameworkServlet 'ApplicationContext'
Sep 24, 2014 5:44:41 PM org.springframework.web.servlet.FrameworkServlet initServletBean
INFO: FrameworkServlet 'ApplicationContext': initialization started
Sep 24, 2014 5:44:41 PM org.springframework.context.support.AbstractApplicationContext prepareRefresh
INFO: Refreshing WebApplicationContext for namespace 'ApplicationContext-servlet': startup date [Wed Sep 24 17:44:41 IST 2014]; root of context hierarchy
Sep 24, 2014 5:44:42 PM org.springframework.beans.factory.xml.XmlBeanDefinitionReader loadBeanDefinitions
INFO: Loading XML bean definitions from ServletContext resource [/WEB-INF/ApplicationContext-servlet.xml]
Sep 24, 2014 5:44:43 PM org.springframework.beans.factory.support.DefaultListableBeanFactory preInstantiateSingletons
INFO: Pre-instantiating singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory@256b49: defining beans [org.springframework.web.servlet.resource.DefaultServletHttpRequestHandler#0,org.springframework.web.servlet.handler.SimpleUrlHandlerMapping#0,org.springframework.web.servlet.handler.BeanNameUrlHandlerMapping,org.springframework.web.servlet.mvc.HttpRequestHandlerAdapter,org.springframework.web.servlet.mvc.SimpleControllerHandlerAdapter,org.springframework.context.annotation.internalConfigurationAnnotationProcessor,org.springframework.context.annotation.internalAutowiredAnnotationProcessor,org.springframework.context.annotation.internalRequiredAnnotationProcessor,org.springframework.context.annotation.internalCommonAnnotationProcessor,trackComplaintsController,viewResolver,trackcomplainsdao,trackcomplaintservice,dataSource,org.springframework.context.annotation.ConfigurationClassPostProcessor$ImportAwareBeanPostProcessor#0]; root of factory hierarchy
Sep 24, 2014 5:44:43 PM org.springframework.web.servlet.handler.AbstractUrlHandlerMapping registerHandler
INFO: Mapped URL path [/**] onto handler 'org.springframework.web.servlet.resource.DefaultServletHttpRequestHandler#0'
Sep 24, 2014 5:44:43 PM org.springframework.jdbc.datasource.DriverManagerDataSource setDriverClassName
INFO: Loaded JDBC driver: oracle.jdbc.driver.OracleDriver
Sep 24, 2014 5:44:43 PM org.springframework.web.servlet.FrameworkServlet initServletBean
INFO: FrameworkServlet 'ApplicationContext': initialization completed in 1883 ms
Sep 24, 2014 5:44:43 PM org.apache.coyote.AbstractProtocol start
INFO: Starting ProtocolHandler ["http-bio-8080"]
Sep 24, 2014 5:44:43 PM org.apache.coyote.AbstractProtocol start
INFO: Starting ProtocolHandler ["ajp-bio-8009"]
Sep 24, 2014 5:44:43 PM org.apache.catalina.startup.Catalina start
INFO: Server startup in 5693 ms