When my jsp files are inside WEB-INF folder (as /WEB-INF/file.jsp) , I can access them from localhost: 8080/ProjectCtxtRoot/, but I can't access them, if they are placed in /WEB-INF/jsp/file.jsp?
I changed the path in welcome-list tag in web.xml as follows
<welcome-file-list>
<welcome-file>/JSP/fileName.jsp</welcome-file>
</welcome-file-list>
I also changed the dispatcher-servlet.xml as follows
<bean id="jspViewResolver"
class="org.springframework.web.servlet.view.InternalResourceViewResolver"
p:prefix="/WEB-INF/jsp/"
p:suffix=".jsp" />
Still it doesn't work. Url used for above case are
localhost:8080/ContextRoot/jsp/
localhost:8080/ContextRoot/jsp/fileName.jsp
localhost:8080/ContextRoot/jsp/fileName
and it doesn't work for any of the above urls.
But it was working when
<welcome-file-list>
<welcome-file>/fileName.jsp</welcome-file>
</welcome-file-list>
dispatcher-servlet.xml as follows
<bean id="jspViewResolver"
class="org.springframework.web.servlet.view.InternalResourceViewResolver"
p:prefix="/WEB-INF/"
p:suffix=".jsp" />
Url used for above case is localhost:8080/ContextRoot/ and it works.
I use tomcat v 7.0 server. I refresh my project in Eclipse IDE, then clean it, build it, build war using mvn clean install, then choose the war from tomcat manager homepage and deploy it. I do this each time.
This is how the diapatcher-servlet.xml looks all through the process. I just change particular section as above said
<?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:mvc="http://www.springframework.org/schema/mvc"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:p="http://www.springframework.org/schema/p"
xsi:schemaLocation="http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.1.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.1.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.1.xsd">
<mvc:annotation-driven/>
<context:component-scan base-package="com.projectName.www" />
<!-- Factory bean that creates the Mongo instance -->
<bean id="mongo" class="org.springframework.data.mongodb.core.MongoFactoryBean">
<property name="host" value="localhost" />
</bean>
<!-- MongoTemplate for connecting and quering the documents in the database -->
<bean id="mongoTemplate" class="org.springframework.data.mongodb.core.MongoTemplate">
<constructor-arg name="mongo" ref="mongo" />
<constructor-arg name="databaseName" value="tableName" />
</bean>
<!-- Use this post processor to translate any MongoExceptions thrown in @Repository annotated classes -->
<bean class="org.springframework.dao.annotation.PersistenceExceptionTranslationPostProcessor" />
<bean id="jspViewResolver"
class="org.springframework.web.servlet.view.InternalResourceViewResolver"
p:prefix="/WEB-INF/jsp/"
p:suffix=".jsp" />
<!-- <bean class="org.springframework.web.servlet.view.tiles2.TilesViewResolver"/>
<bean class=
"org.springframework.web.servlet.view.tiles2.TilesConfigurer"> -->
<!-- <property name="definitions">
<list>
<value>/WEB-INF/views/views.xml</value>
</list>
</property>
</bean> -->
</beans>
This is how my web.xml looks like
<web-app>
<!-- <display-name>Archetype Created Web Application</display-name> -->
<servlet>
<servlet-name>dispatcher</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<!-- <init-param>
<param-name>contextConfigLocation</param-name>
<param-value>/src/main/webapp/WEB-INF/dispatcher-servlet.xml</param-value>
</init-param>-->
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>dispatcher</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/dispatcher-servlet.xml</param-value>
</context-param>
<!-- <listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener> -->
<welcome-file-list>
<welcome-file>/fileName.jsp</welcome-file>
</welcome-file-list>
</web-app>
Ok. It works when I moved the entire jsp folder from /webapp/WEB-INF/jsp/fileName.jsp to /webapp/jsp/fileName.jsp. I would like to know 1. why it works now? 2. Is this the correct way to do things? 3. It works when the url is localhost:8080/CtxtRoot/jsp/or localhost:8080/CtxtRoot/jsp/search.jsp, but it doesn't work for localhost:8080/AnnaUnivResults/jsp/search. Why is it so?
<welcome-file>
is completely unrelated to a SpringViewResolver
. Your question is currently all over the place. You'll have to clarify your context path and the exact HTTP request you send in each scenario. If the request is handled by Spring'sDispatcherServlet
, you'll need to show the handler as well.