aspose file tools*
The moose likes Spring and the fly likes simple Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Spring
Bookmark "simple "Hello World" webapp displays home page but does not populate fields on home page" Watch "simple "Hello World" webapp displays home page but does not populate fields on home page" New topic
Author

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

Stuart Rogers
Ranch Hand

Joined: Oct 02, 2008
Posts: 140
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
Ayan mallick
Ranch Hand

Joined: Nov 17, 2012
Posts: 46
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

Joined: Oct 02, 2008
Posts: 140
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

Joined: Nov 17, 2012
Posts: 46
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
 
 
subject: simple "Hello World" webapp displays home page but does not populate fields on home page