• 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
  • Tim Cooke
  • Ron McLeod
  • paul wheaton
  • Jeanne Boyarsky
Sheriffs:
  • Paul Clapham
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
  • Himai Minh
Bartenders:

How dispatcher-servlet.xml works

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

i am completely new to spring,

i understood that urlMapping in dispatcher servlet will tell which controller to handle using <prop key="testing.htm">indexController</prop>.

In controller we will mention the logical name. Using that, the viewresolver adds the p:prefix and p:suffix to the logical name and shows the view.

Now my question is, if i have view files in different directory, how will i mention the correct view resolver for the request.

If my understanding or question is wrong please correct me.

Thanks In Advance,

Bennet Xavier. X
 
Ranch Hand
Posts: 1936
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You can have multiple view resolvers.
 
Bennet Xavier
Ranch Hand
Posts: 162
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

i tried that,



this is what i added in the dispatcher-servlet.xml

the testing.jsp file is in WEB-INF directory, but its giving resource not found 404 error

SEVERE: PWC6117: File "D:\tech\Spring\build\web\WEB-INF\jsp\testing.jsp" not found this is error i am getting in server console.
Thanks,
Bennet

 
Hong Anderson
Ranch Hand
Posts: 1936
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You should specify order of viewResolver1 to 1, and order of viewResolver to 2.
 
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

Are you using a simpleformcontroller or abstractformcontroller?

depending on that i can give you a proper solution
 
Bennet Xavier
Ranch Hand
Posts: 162
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

i got that, once i change the order value as mentioned, its working fine.

it showing the file in /WEB-INF/

then the files in /WEB-INF/jsp are not working. 404 RESOURCE NOT FOUND

i think it checks for the viewresolver which has lowest order value and assigns, thats it.

its not taking the other viewresolver in the dispatcher-servlet.xml


Hi yusuf nazir,

i am using SimpleFormController,

if i am using abstractformcontroller, what i need to do.

thanks,

Bennet Xavier. X
 
yusuf nazir
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Bennet,

When i build spring app i use the a views file to handle the views.
for example, I have a springweb-views.xml


as you can see the xml file will handle the getting the right jsp. All you have to do is call the view name, either "continue" or "anotherView".
this xml file is placed besides the servlet and web.xml files.

this should at least help to resolve your "no resources found" error.

keep us posted if that was what you want or not.
 
Bennet Xavier
Ranch Hand
Posts: 162
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi yusuf nazir,

if you are using a separate file for view. Then do i need map in web.xml or any-other place.

i tried modifying the dispatcherservlet.xml with what ever you posted, its not working.

my dispatcher servlet.xml look as mentioned below.



how will i call this jsp, i mean what name in the url i have to mention. Just testing.htm or else the url mentioned in the bean you have given(continue or anotherView).

Thanks
Bennet.

 
yusuf nazir
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi bennet,

I made the neccesary changes to dispatcher-servlet.xml


ok now i created another file called spring-views.xml. place this in the same folder where the dispatcher-servlet.xml is located.


best thing to do is to try to build is simple as possible.

spring follows a very simple flow. I'll try to explain it.
If I'm not mistaken you;re project folder is as follow:

When you're application starts up it will look in the web.xml. The web.xml has a welcome-file-list that tells spring where to start.
the welcome-file-list has a lot of addresses, but only the first acceptable one is used on implementation.
In this case it's our redirect.jsp




the redirect.jsp tells spring which url to parse to generate the requested page.
here we tell the application to always start with the index.htm url.
so spring will now activate the right controller and the is the indexcontroller because index.htm is mapped with indexcontroller in your dispatcher servlet.



your indexcontroller is simpleformcontroller as you said so it should be something like this:


This is a very simpleformcontroller that just renders a page and does nothing else. As you see constructor has been defined for loading a bean on implementation of the controller. This is also configured in your dispacther-servlet.xml where you give your commandclass. A simpleform controller is meant to get information from the page when the form is submitted. the information is thus stored in the commanclass.

you will also notice that the dispachter servlet has a formview defined as "index". so spring will load up the corresponding jsp. This is configured in the spring-views.xml

By the way. I use the following tools: eclipse europa 3.3, maven 2.0 and deploy on tomcat 5.5
Do post what you use to build your app.

hope this helps

reply
    Bookmark Topic Watch Topic
  • New Topic