【问题标题】:Problem with model, view and controller模型、视图和控制器的问题
【发布时间】:2010-08-30 19:41:01
【问题描述】:

我做一个 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>

【问题讨论】:

  • 我认为这段代码可能是问题 contextConfigLocation/WEB-INF/applicationContext.xmlvalue> org.springframework.web.context.ContextLoaderListener

标签: jsp spring-mvc jstl


【解决方案1】:

不推荐使用整个 Controller 类层次结构。 Spring MVC 的首选用法是使用带有@Controller 注释的类。

在您在这条路上走得太远之前,您可能需要阅读this example

【讨论】:

    【解决方案2】:

    尝试将您的配置更改为此并报告如果您仍然遇到问题...

    <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>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-08-23
      • 2011-06-26
      • 1970-01-01
      • 1970-01-01
      • 2011-12-28
      相关资源
      最近更新 更多