wood burning stoves 2.0*
The moose likes Spring and the fly likes Spring 3.0 MVC - Not getting to the Controller.java Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Spring
Bookmark "Spring 3.0 MVC - Not getting to the Controller.java" Watch "Spring 3.0 MVC - Not getting to the Controller.java" New topic
Author

Spring 3.0 MVC - Not getting to the Controller.java

Mimi Tam
Ranch Hand

Joined: Mar 05, 2010
Posts: 121

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.

Please HELP!


Jeanne Boyarsky
author & internet detective
Marshal

Joined: May 26, 2003
Posts: 30938
    
158

Moving to our Spring forum since I don't see any connection to JDBC.


[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 17259
    
    6

Based on your web.xml and see this



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.

Mark


Perfect World Programming, LLC - Two Laptop Bag - Tube Organizer
How to Ask Questions the Smart Way FAQ
Mimi Tam
Ranch Hand

Joined: Mar 05, 2010
Posts: 121
Hi Mark,

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.

Many Thanks


Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 17259
    
    6

So in your debugging you got to the last line?

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
Hi Mark,

I have below and my view files are in "/WEB-INF/jsp/".

<bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="viewClass" value="org.springframework.web.servlet.view.JstlView"/>
<property name="prefix" value="/WEB-INF/jsp/"/>
<property name="suffix" value=".jsp"/>
</bean>

My same problem still exists and I'm about to pull all my hair out. Any other ideas?

Thanks
Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 17259
    
    6

So then it is looking for

/WEB-INF/jsp/Book.jsp.jsp

Which I doubt is the actual file name.

I assume your file name is Book.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
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.


Many Thanks
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14688
    
  16


Why are you mapping the DispatcherServlet to this url ?


[My Blog]
All roads lead to JavaRanch
Mimi Tam
Ranch Hand

Joined: Mar 05, 2010
Posts: 121
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?

Thank you very much and hoping for more ideas.




Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 17259
    
    6

"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
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.
Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 17259
    
    6

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

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.

Much Obliged.

Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14688
    
  16

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
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://aspose.com/file-tools
 
subject: Spring 3.0 MVC - Not getting to the Controller.java