在spring mvc中获取jsp中的URL

时间:2013-09-03 08:07:58

标签: spring jsp spring-mvc

您好我正在Spring mvc应用程序中进行示例应用程序。我使用Jsp作为视图。 当我运行程序时,我得到的网址为eg- http://localhost/Project/login.html。如何将网址设为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>

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

提前致谢

2 个答案:

答案 0 :(得分: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>

答案 1 :(得分:0)

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

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

相关问题