我做一个hello world非常简单,现在我想要捕获一个类的数据而我不能这样做,当我编译项目完美时,当我运行项目时显示错误:Estado HTTP 404,我不知道如何解决问题,请帮助。
我的控制器是welcomeController
public ModelAndView handleRequest(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
List usuarios = catalogFacadeImpl.getUserList();
logger.info("Returning hello view with " + usuarios);
return new ModelAndView("welcome", "usuarios", usuarios);
我的模型是branch_try_htmlModulo-servlet.xml
<bean name="/welcome.htm" class="com.bamboo.catW3.business.impl.WelcomeController"/>
<bean id="urlMapping" class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">
<property name="mappings">
<props>
<prop key="/welcome.htm">branch_try_htmlModulo</prop>
</props>
</property>
</bean>
<bean id="beerListController" class="com.bamboo.catW3.business.impl.WelcomeController">
<property name="catalogFacadeImpl" ref="catalogFacadeTarget"/>
</bean>
<bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="viewClass" value="org.springframework.web.servlet.view.JstlView"></property>
<property name="prefix" value="/WEB-INF/jsp/"></property>
<property name="suffix" value=".jsp"></property>
</bean>
我的观点是welcome.jsp
<html>
<head><title>Hello :: Spring Application</title></head>
<body>
<table border="0">
<c:forEach items="${usuarios}" var="usuario">
<tr>
<td><c:out value="${usuario.user_name}"/></td>
</tr>
</c:forEach>
</table>
</body>
</html>
我的web.xml是
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/applicationContext.xml</param-value>
</context-param>
<listener>
<listener-class> org.springframework.web.context.ContextLoaderListener
</listener-class>
</listener>
<servlet>
<servlet-name>branch_try_htmlModulo</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet
</servlet-class>
<load-on-startup>2</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>branch_try_htmlModulo</servlet-name>
<url-pattern>*.htm</url-pattern>
</servlet-mapping>
<welcome-file-list>
<welcome-file>
index.jsp
</welcome-file>
</welcome-file-list>
答案 0 :(得分:2)
不推荐使用整个Controller类层次结构。 Spring MVC的首选用法是使用@ Controller-annotated classes。
在你走这条路太远之前,你可能想要阅读this example。
答案 1 :(得分:0)
尝试将配置更改为此并报告您是否仍有问题...
<bean id="welcomeController" class="com.bamboo.catW3.business.impl.WelcomeController"/>
<bean id="urlMapping" class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">
<property name="mappings">
<props>
<prop key="/welcome.htm">welcomeController</prop>
</props>
</property>
</bean>