• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Spring 3.0 MVC - Not getting to the Controller.java

 
Mimi Tam
Ranch Hand
Posts: 121
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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
Posts: 33674
316
Eclipse IDE Java VI Editor
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Moving to our Spring forum since I don't see any connection to JDBC.
 
Mark Spritzler
ranger
Sheriff
Posts: 17276
6
IntelliJ IDE Mac Spring
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Mimi Tam
Ranch Hand
Posts: 121
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 17276
6
IntelliJ IDE Mac Spring
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 121
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 17276
6
IntelliJ IDE Mac Spring
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 121
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Why are you mapping the DispatcherServlet to this url ?
 
Mimi Tam
Ranch Hand
Posts: 121
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 17276
6
IntelliJ IDE Mac Spring
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"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
Posts: 121
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 17276
6
IntelliJ IDE Mac Spring
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 121
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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
Pie
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 121
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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

 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic