• 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

Index and web.xml page in spring

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

I am trying to follow an already build spring application. I have an index page in my spring application which is as following

index.jsp



My web.xml file is



Now i have two question here

(1) When application is run, spring container will hit index.jsp which is configured as welcome page here and will load it. On index.jsp, it will execute the line

and then since it is a sendRedirect , it will search for this URL in controller class and do the processing as per logic of corresponding controller section.
My question is why we have written

in index.jsp. what is its output. Will it ever get executed? because moment it finds sendRedirect() function in index.jsp, the flow will go to controller class and will execute according to logic written there. Here, from controller class it gets redirected to actual login page without doing anything.




(2) My second question is what is <context_param> tag in web.xml file mentioned above and what is contextConfigLocation as its <param-name> and what is its use. Please explain in simple language so that i may understand it. probably with an example. Thanks. I tried to google it but almost everywhere it was high technical language rather than simple understandable one. Thanks.
 
Bartender
Posts: 3648
16
Android Mac OS X Firefox Browser Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The <spring:message> tag is used for resource bundle where user can change language from English to another and back without hard-coding the actual message/text in the jsp file.

The resource bundle files are usually properties in the "resources" folder of your project hierarchy.

Does the login page have similar tags, are those displayed?


As for the 2nd question, the <context-param> tag tells the web-app where to load the Spring configuration, in your case inside WEB-INF/springWeb-servlet.xml file. In this file is where you should able to find that resource bundle file mapping along with other Spring stuff.
 
rammie singh
Ranch Hand
Posts: 122
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Tsang,
First of all thanks for your reply. I can really understand now the concept of tag <spring: message >
however i still have one doubt related to it and just wanted to confirm

In my index page, will the <spring:message> tag will ever be executed? Will the value of variable "title.welcomeMsg" from required properties file be displayed here?
(i guess no, because before coming to this line, control of flow is being passed on to controller for the link "login/directLogin.htm" and flow goes to loginPage.jsp
page from the controller.Also i am not getting value of variable "title.welcomeMsg" getting displayed on loginPage.jsp page). I am just trying to understand the
purpose of putting on index.jsp.


2nd

Regarding <Context-Param> tag,
I dont see this tag used for every spring application. Say for example in hello world example HelloWorldInSpring

So when you say "this tag is used to tell the web-app where to load Spring configuration", does not it gets loaded in hello world example above?
So basically just wanted to understand what is the difference when we use and don't use tag with
is there some default loading/picking when we dont mention this ?
 
K. Tsang
Bartender
Posts: 3648
16
Android Mac OS X Firefox Browser Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Looking at the web.xml, <context-param> tag isn't telling where to load the Spring configuration, my bad.

I don't know if your example app needs a <context-param>. Not sure if this is correct but basically this tag tells Spring that "annotations" will be used in code and tell the container to support/enable it.



As for the Spring config, it's in the <servlet> tag's <init-param>. In my example, the Spring config file in /WEB-INF/config/dispatcher-servlet.xml

 
K. Tsang
Bartender
Posts: 3648
16
Android Mac OS X Firefox Browser Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Depending on where you put the <spring:message>, it may display.

If you doing redirection (say using javascript) in the JSP, then your spring:message before the redirection should be displayed.

If you doing redirection in the servlet/controller, then the original JSP wouldn't even get rendered.
 
Why should I lose weight? They make bigger overalls. And they sure don't make overalls for tiny ads:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic