Spring 3.0 MVC - Not getting to the Controller.java
Mimi Tam
Ranch Hand
Joined: Mar 05, 2010
Posts: 121
posted
0
I am running Spring 3.0 with some older Spring code that does not use Annotations. I do not want to change the code but I could not get into the Controller code even though I think my mapping looks ok. I am not sure if an HTTP request was generated (when I clicked on the Test.html) or even captured by the context loader listener but I know the corresponding Controller was not entered.
Any ideas and help would be greatly appreciated.
I get the Test.jsp page displayed but the testController.java was not entered so I could not get any HTTP request/response messages.
I would expect in your WEB-INF directory you have two files
applicationContext.xml
TestApp-servlet.xml
because those are the naming standards when you do not include a <context-param> to point to your application config xml file
and an <init-param> in your servlet tag to point to the config file for your web components/controller.
So based on what you posted, your App-Servlet.xml is not even being read in, because your web.xml know nothing about it.
Thank you for your response. Actually, I do have those 2 files properly named. In posting the code, I changed the name of the App and other stuff for proprietary reasons.
I am actually inside the Controller (saw from the debugger) but did not go into ModelAndView where I have the business logic.
I am quite desperate to fix this. I am running Spring 3.0 but the code that I am working on is Spring 2.x. I want to get a sample Spring 3.0 Dynamic Web Project to run on my Tomcat successfully so I have something to go by. But, I couldn't find one that work for me (i.e. download code, import to Eclipse and run).
It will be great if you know of a DYNAMIC WEB PROJECT that runs on Server and is a good working template that I can use....I would be tremendously grateful.
return new ModelAndView("Book.jsp","bookList", bookList);
Do you have a viewResolver setup in your configuration.
This last part is taking that "Book.jsp" and resolving that string to a view page. I would expect your book.jsp file is in your WEB-INF/views directory, is this correct.
Do you want to use the internalViewResolver which prepends and appends strings to your view string your return. so
Now the above is not 100% correct. I don't remember the actual class package and property names.
Mark
Mimi Tam
Ranch Hand
Joined: Mar 05, 2010
Posts: 121
posted
0
Hi Mark,
I have below and my view files are in "/WEB-INF/jsp/".
So remove the ".jsp" from your ModelAndView object
like this
return new ModelAndView("Book","bookList", bookList);
Mark
Mimi Tam
Ranch Hand
Joined: Mar 05, 2010
Posts: 121
posted
0
Oh Mark, that is definitely a problem. Thank you very much! I took the ".jsp" out.
However, my problem is that debugger never stopped inside ModelAndView(). It only called setBookManager() twice within the Controller but never got inside ModelAndView().
My BooksManager class:
My BookDao:
...book.jsp is in WEB-INF/jsp/...what else shall I tell you...
I am still struggling. Any ideas will be greatly appreciated.
Sorry, Christophe. That was a typo when I was trying to substitute all the proprietary names to 'test' for this forum.
My code is more like this in web.xml:
And, it did get to my Controller class but never called ModelAndView() My main processing logic is inside ModelAndView() before rendering data to the View but the execution thread never got inside ModelAndView(). What could have caused this?
"My main processing logic is inside ModelAndView() "
What do you mean, you can't put any code in the ModelAndView class. That is a Spring class, you don't have access or the ability to add code there. So that statement isn't making any sense to me.
ModelAndView is just a String and a Map inside of it. The String for the view name and the Map for the object you want to put into the Model.
Mark
Mimi Tam
Ranch Hand
Joined: Mar 05, 2010
Posts: 121
posted
0
I am sorry. I think I was not making myself very clear or I was simply not getting it. Please see my Controller code segment below. I set a break point inside the ModelAndView HandleRequest() method but it never got to that break point. I am relying on getting data for my http request/response messages from client and use it to fetch data from database and have it render out to the View (book.jsp). Hope I am making some sense here. If not, please correct.
Also, if I may reiterate, the debugging did stop at the statement "booksManager = obj" inside setBooksManager().
Many Thanks and looking forward to any ideas to try out.
Are you sure your mapping is correct with the servlet-mapping, and also the UrlMappingHandler class.
If you are using Spring 3.0, why are you implementing the Controller interface. That is actually an older way of doing Spring MVC.
In Spring 3.0 the @MVC is the more current approach doing annotations in your Controller POJO class.
To be honest, and I am not trying to be mean. But I highly recommend you going to springframework.org and reading the Spring 3.0 documentation. Or find a nice tutorial on Spring 3.0, at InfoQ there is a nice video on what is new in Spring MVC.
Trying to debug your issue at this point is extremely difficult through forum means, there is just so many places that might be wrong that we probably won't quite get it.
I hope that helps
Mark
Mimi Tam
Ranch Hand
Joined: Mar 05, 2010
Posts: 121
posted
0
Hi Mark,
I totally agree. I really like the expanded Annotations and read a bit about it. The code base that I am working on now was written for Spring 2.x. I need to make it run in 3.0 and make modifications. Short of rewriting everything (perhaps I really need to), I want to get it working first in Spring 3.0 with Hibernate 3.0, MySQL 5.1 and Tomcat v6. This code ran in Spring 2.6.1.
Thanks for looking at my problems and suggested good solutions.
As a side note, it is recommended to respect some basic conventions, like package and class naming. You have a testController class in a "TestApp.Web" package. You should rename the class TestController, and the package "testApp.web". You'd better rename JSP files to lowercase too : Test.jsp -> test.jsp.
Mimi Tam
Ranch Hand
Joined: Mar 05, 2010
Posts: 121
posted
0
Yes, most certainly. Thank you Christophe.
I had to do quite a lot of editing to the code before I could post it online for proprietary reasons. I got sloppy sometimes with the repetitive editing. But, yes, I am a big proponent in sticking to standards, it makes life easier that way...
Thanks again
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to
run our stuff on 16 servers instead of 3.
subject: Spring 3.0 MVC - Not getting to the Controller.java