user2083175
user2083175

Reputation: 133

Get URL in jsp in spring mvc

Hi i am doing a sample application in spring mvc application.I am using Jsp as view. when i run the program i am getting the url as eg- http://localhost/Project/login.html. How can i get the url as http://localhost/Project/login.jsp.

This is my 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> 

Thanks in advance

Upvotes: 0

Views: 421

Answers (2)

Deepak R Shankar
Deepak R Shankar

Reputation: 86

Your dispatcher servlet has extension mapping for html. change your servlet mapping to

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

Upvotes: 0

chinna_82
chinna_82

Reputation: 6403

on bottom of your web.xml.
Change this

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

to

<welcome-file-list>
    <welcome-file>login.jsp</welcome-file>
</welcome-file-list>

Upvotes: 1

Related Questions