Spring MVC注释中未出现的复选框列表



我试图在Spring MVC中实现带有注释的动态复选框列表。所以,我试了这个:

在home.jsp:

             <c:forEach items="${categories}" var="cat">
                <tr>
                    <td><form:checkbox path="catrgo" value="${category}"
                            label="${cat.categoryId}" /></td>
                    <td><c:out value="${cat.category}" /></td>
                </tr>
            </c:forEach>

And In HomeController:@ controller@RequestMapping(value = "/home")公共类HomeController {

@RequestMapping(method = RequestMethod.GET)
public String showForm() {
    FeedDomain feedDomain = new FeedDomain();
    System.out.println("Called");
    CategoryService categoryService = new CategoryService();
    try {
        List<CategoryDomain> categoryDomainList = new   ArrayList<CategoryDomain>();
        CategoryDomain categoryDomain = new CategoryDomain();
        categoryDomain.setCategory("aaa");
        categoryDomain.setCategoryId(11111);
        System.out.println("Size is " + categoryDomainList.size());
    } catch (Exception exception) {
    }
    return "home";
}

现在我将使用标签从index.jsp到home.jsp,但问题是showForm方法没有被调用。原因是什么呢?

我在下面发布完整的流程:

这里是welcome.jsp,我从这里调用home.jsp

       <body>
             <a href="home.jsp" class="btn btn-success btn-large disabled">Get
                        Us Feeds Now</a>
       </body>

现在我已经简化了home.jsp的呈现:

    <body>
<br /> &nbsp;&nbsp;
<span class="badge badge-info"><h1>Chat Booster</h1></span>
<div class="leftHeader">
    <h1>
        <small>Subtext for header</small>
    </h1>
</div>
<br></br>
<br></br>
    </body>

,主页控制器为:

         @Controller
        @RequestMapping(value = "/home")
    public class HomeController {
@RequestMapping(method = RequestMethod.GET)
public String showForm() {
    FeedDomain feedDomain = new FeedDomain();
//  model.addAttribute("feedDomain", feedDomain);
    System.out.println("Called");
    CategoryService categoryService = new CategoryService();
    return "home";
}

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>HelloWorldExampleWithSpring3MVCInEclipse</display-name>
<servlet>
    <servlet-name>Spring MVC Dispatcher Servlet</servlet-name>
    <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-  class>
    <init-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>
            /WEB-INF/app-config.xml
        </param-value>
    </init-param>
    <load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
    <servlet-name>Spring MVC Dispatcher Servlet</servlet-name>
    <url-pattern>/</url-pattern>
</servlet-mapping>
<welcome-file-list>
    <welcome-file>index.jsp</welcome-file>
</welcome-file-list>
    </web-app>

app-config.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:context="http://www.springframework.org/schema/context"
xmlns:mvc="http://www.springframework.org/schema/mvc"
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">
<context:component-scan base-package="com.controller" />
<!-- Resolves view names to protected .jsp resources within the /WEB-INF/views 
    directory -->
<bean id="viewResolver"
    class="org.springframework.web.servlet.view.InternalResourceViewResolver">
    <property name="prefix" value="" />
    <property name="suffix" value=".jsp" />
</bean>
    </beans>

我的jsp页面仅在webcontent文件夹中(不在web-inf中)。现在我将稍后寻找主要问题,但第一点是showForm()方法没有被调用,因为系统没有在控制台上打印任何东西。如果我将home.jsp作为应用程序的默认页面,则调用该方法,但不是通过给定的方法。有人能对此发表评论吗?

您的链接不正确,您需要调用控制器动作而不是jsp:

   <body>
       <c:url var="homeLink" value="/home"/>
       <a href="${homeLink}" class="btn btn-success btn-large disabled">Get Us Feeds Now</a>
   </body>

最新更新