• 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

simple "Hello World" webapp displays home page but does not populate fields on home page

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

Built up a Hello World webapp using Eclipse/Maven/Hibernate/Spring/MySQL.
Compiles and deployes fine into my local Tomcat server. I open a browser,
enter "http://localhost:8080/skincare-webapp" , and /WEB-INF/index.jsp does indeed
get displayed BUT none of the fields get filled in by HomeController ie "today"
and "aMsg" don't get populated by the method in HomeController. And the logfile
doesn't contain the "entering" tag, so it seems like the method is never getting called.

So it's close to working, there's just something subtle I'm missing and/or misaligning.
Can anyone tell me what I'm doing wrong?


/index.jsp


/WEB-INF/web.xml


/WEB-INF/spring/appServlet/servlet-context.xml


HomeController.java


Thanks,

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

remove index.jsp which you are having under webcontent folder. because what's happening is request is going straight to default index page instead of hitting
the HomeController's showHomePage method. for spring application naturally we don't put any jsp under webcontent to enforece that every request must go through a controller and to stop accessing any jsp outside controller.


and one more thing is return string from showHomePage method. when we are using InternalResourceViewResolver to resolve view then we should return only the name of the jsp without .jsp extention and folder extension because that's what you have already defined in /WEB-INF/spring/appServlet/servlet-context.xml .

so full path to your jsp : prefix + name returned from showHomePage method + suffix.

so put your index page inside /WEB-INF/views/ and return only index from showHomePage method.

/WEB-INF/views/ + index +.jsp
 
Stuart Rogers
Ranch Hand
Posts: 141
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank You for replying to my plea for help!

I've made the changes you suggested, http://localhost:8080/tester does indeed bring up /WEB-INF/views/index.jsp
but http://localhost:8080/tester/hello throws a 404. the logfile says "No mapping found for HTTP request with URI [/tester/hello] in DispatcherServlet with name 'dispatcher' ".
So I'm closer but still no cigar. Any other suggestions?

Thanks again,

Stuart


/WEB-INF/views/index.jsp


/WEB-INF/views/output.jsp


/WEB-INF/web.xml


/WEB-INF/dispatch-context.xml


HomeController.java
 
Ayan mallick
Ranch Hand
Posts: 46
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Stuart,

please check that in your web.xml you have defined your location of spring config file as



but below you have defined location of your config file as /WEB-INF/dispatch-context.xml which is different.

see your earlier post their you did it perfectly compare it with that.

basically the flow is :

check out the server log when you start up the server. the moment server is started it loads the dispatcher servlet because load-on-startup=1.

if you don't define any special place for config file then default convention is it search for a file named :

dispatcher servlet name in web.xml + -servlet.xml

so you have to put that named file in WEB-INF folder.

otherwise if you have defined any location explicitely like in your application you have done, then you have to make sure you are putting same named file in defined location so that spring container can find the config xml.

Then spring parse the config xml and find base package name like: <context:component-scan base-package="skincare.web"/>
based on your package name spring scan all classes under that package to find all mapping related stuff.
check the log it prints all details of the scanned classes like you class with @controller annotation.

and all above flow happens just when you strat up the server before hitting any url.

Hope it helps you

Thanks

Ayan
 
He loves you so much! And I'm baking the cake! I'm going to put this tiny ad in the cake:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic