0

嗨,我正在 spring mvc 应用程序中做一个示例应用程序。我使用 Jsp 作为视图。当我运行程序时,我得到的 url 为 eg- http://localhost/Project/login.html。我怎样才能得到 url 作为http://localhost/Project/login.jsp.

这是我的 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>Project</display-name>
 <welcome-file-list>
    <welcome-file>login.jsp</welcome-file>

</welcome-file-list>
<servlet>
    <servlet-name>Dispatch</servlet-name>
    <servlet-class>
       org.springframework.web.servlet.DispatcherServlet

    </servlet-class>

    <load-on-startup>1</load-on-startup>
</servlet>

<servlet-mapping>
    <servlet-name>Dispatch</servlet-name>
    <url-pattern>*.html</url-pattern>
</servlet-mapping>
<welcome-file-list>
    <welcome-file>index.html</welcome-file>
</welcome-file-list>

调度-servlet.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">
    <bean id="messageSource"  class="org.springframework.context.support.ReloadableResourceBundleMessageSource">
     <property name="basename" value="/WEB-INF/messages" />
     <property name="cacheSeconds" value="3000" />
   </bean>
   <context:component-scan base-package="credentials" />

   <mvc:annotation-driven />
     <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
     <property name="prefix" value="/WEB-INF/jsp/" />
     <property name="suffix" value=".jsp" />
    </bean>

   </beans> 

提前致谢

4

2 回答 2

1

在 web.xml 的底部。
改变这个

<welcome-file-list>
    <welcome-file>index.html</welcome-file>
</welcome-file-list>

<welcome-file-list>
    <welcome-file>login.jsp</welcome-file>
</welcome-file-list>
于 2013-09-03T08:12:04.830 回答
0

您的调度程序 servlet 具有 html 的扩展映射。将您的 servlet 映射更改为

<servlet-mapping> <servlet-name>Dispatch</servlet-name> <url-pattern>/</url-pattern> </servlet-mapping>

于 2014-03-17T19:45:03.553 回答