• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Spring MVC: HTML Page loading, HTML views and Controller workflow.

 
Ranch Hand
Posts: 208
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

I am a newbie to Spring. I am working with a very basic application. The workflow is

1) CustomerDtls.html page collecting customer data i.e. name, email address, phone #
2.) on submitting the data, save it to the in memory database

I am testing the above with apache-tomcat-8.0.18 server with exploded directory deployment. Deployment no issues.

Below is my deployment Structure

<CustomerService>
------------------------META-INF

-------------------------static
----------------------------------CustomerDtls.html
----------------------------------ThankYou.html

-------------------------WEB-INF
------------------------------------classes
------------------------------------lib
------------------------------------spring
------------------------------------views
------------------------------------web.xml



in the web-inf/spring/servlet.context.xml i have the following configuration


<!-- Handles HTTP GET requests for /resources/** by efficiently serving up static resources in the ${webappRoot}/resources directory -->
<resources mapping="/resources/**" location="/resources/" />

<!-- Handles HTTP GET requests for /static/** by efficiently serving up static resources in the ${webappRoot}/static directory -->
<resources mapping="/static/**" location="/static/" />


<!-- Resolves views selected for rendering by @Controllers to .jsp resources in the /WEB-INF/views directory -->
<beans:bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<beans:property name="prefix" value="/WEB-INF/views/" />
<beans:property name="suffix" value=".jsp" />
</beans:bean>


I have a CustomerDtlsController.java as below



When i go to the browser and type http://localhost:8080/CustomerService/CustomerDtls.html, it does not load the .html page, workflow starts with CustomerDtlsController.customerFormSubmit() and displays an 404 message saying requested resource /views/static/ThankYou.html.jsp is not available.

i changed the static resource mapping from

<resources mapping="/static/**" location="/static/" />

to

<resources mapping="/*.html**" location="/static/" />

After doing the above change i am able to atleast load the ThankYou.html as http://localhost:8080/CustomerService/ThankYou.html, else would get 404 error message.

Below is what i want to know:

1.) CustomerDtls.html is a static file and i want to load it without dispatcher servlet routing it to CustomerDtlsController, on submit of the details the controller needs to be approached.
2.) If the view returned from controller is a plain .html file how do we configure it, so that view controller knows to look in WEB_ROOT/static folder and not WEB_INF/VIEWS


Please help me.

Best Regards,
REshma

 
Ranch Hand
Posts: 672
4
Eclipse IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Here, you configure your views to be located in /WEB-INF/views and JSP pages, but you need plain html as views and which are under <WEB_ROOT>/static and not WEB-INF/views.

change this viewresolver appropriately or remove it and return your views accordingly in the controller.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic