Spring MVC url无法正常工作

时间:2012-12-28 05:53:37

标签: spring-mvc

我有这个页面welcome.jsp:

          <body>

                <h1>Heading</h1>
                <p>Tagline</p>
                <p align="center">
                    <c:url var="homeLink" value="/home" />
                    <a href="${homeLink}" class="btn btn-success btn-large disabled">Get
                        Us Feeds Now</a>
                </p>


         </body>
         </html>

但是当我点击链接时,我没有转到home.jsp home.jsp的控制器是:

     @Controller
     @RequestMapping(value = "/home")
     public class HomeController {

@RequestMapping(method = RequestMethod.GET)
public String showForm() {
    System.out.println("Called");

    return "home";
}
  }

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

请注意,我的网页仅在webcontent文件夹中,而不在web-inf。

我真的陷入了这个问题。请帮帮我...

1 个答案:

答案 0 :(得分:0)

我不确定您的控制器是否被调用,但我正在尽我所能

<强> 1。如果未调用控制器:

检查web.xml并将网址格式设为/

change if you have like this
   <url-pattern>*.html</url-pattern>
to
       <url-pattern>/</url-pattern>

<强> 2。如果控制器调用:

Give suffix value (path of your jsps) of your view resolver as

  /WEB-INF/views or any other