Win a copy of Practical SVG this week in the HTML/CSS/JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

redirect and forward are not working

 
Joe McTigue
Ranch Hand
Posts: 71
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm learning how to use redirect and forward, then testing to see how the output works with a couple of system.out.printlns.
For some reason my console output never prints the
of the addMinutes method of my controller, please help me figure this out. 

currently I'm getting the following output on my console:

INFO: Server startup in 2058 ms
Nov 08, 2016 12:48:34 PM org.apache.catalina.core.ApplicationContext log
INFO: Initializing Spring FrameworkServlet 'fitTrackerServlet'
Nov 08, 2016 12:48:34 PM org.springframework.web.servlet.DispatcherServlet initServletBean
INFO: FrameworkServlet 'fitTrackerServlet': initialization started
Nov 08, 2016 12:48:34 PM org.springframework.web.context.support.XmlWebApplicationContext prepareRefresh
INFO: Refreshing WebApplicationContext for namespace 'fitTrackerServlet-servlet': startup date [Tue Nov 08 12:48:34 EST 2016]; root of context hierarchy
Nov 08, 2016 12:48:34 PM org.springframework.beans.factory.xml.XmlBeanDefinitionReader loadBeanDefinitions
INFO: Loading XML bean definitions from ServletContext resource [/WEB-INF/config/servlet-config.xml]
Nov 08, 2016 12:48:36 PM org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping register
INFO: Mapped "{[/greeting]}" onto public java.lang.String com.pluralsight.controller.HelloController.sayHello(org.springframework.ui.Model)
Nov 08, 2016 12:48:36 PM org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping register
INFO: Mapped "{[/addMinutes]}" onto public java.lang.String com.pluralsight.controller.MinutesController.addMinutes(com.pluralsight.model.Exercise)
Nov 08, 2016 12:48:36 PM org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping register
INFO: Mapped "{[/addMoreMinutes]}" onto public java.lang.String com.pluralsight.controller.MinutesController.addMoreMinutes(com.pluralsight.model.Exercise)
Nov 08, 2016 12:48:36 PM org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter initControllerAdviceCache
INFO: Looking for @ControllerAdvice: WebApplicationContext for namespace 'fitTrackerServlet-servlet': startup date [Tue Nov 08 12:48:34 EST 2016]; root of context hierarchy
Nov 08, 2016 12:48:36 PM org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter initControllerAdviceCache
INFO: Looking for @ControllerAdvice: WebApplicationContext for namespace 'fitTrackerServlet-servlet': startup date [Tue Nov 08 12:48:34 EST 2016]; root of context hierarchy
Nov 08, 2016 12:48:36 PM org.springframework.web.servlet.DispatcherServlet initServletBean
INFO: FrameworkServlet 'fitTrackerServlet': initialization completed in 2002 ms
exercising: 17

I running this in a Java 8 compiler,
using Spring STS version 3.8.1 IDE,
Tomcat version: 9,
Maven version: 3.3.9,
spring-webmvc version: 4.3.2,
servlet-api version: 2.5,
jstl version: 1.2

Here is my controller code:

here is my JSP code:


Thanks for any help you can offer.
Let me know if you need to see anything else.
-Joe
 
Ankit Garg
Sheriff
Posts: 9591
34
Android Google Web Toolkit Hibernate IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is your application working and println is not displayed? What is the URL that you enter in the browser and do you actually see addMoreMinutes.html in the browser? Can you also share your spring configuration...
 
Joe McTigue
Ranch Hand
Posts: 71
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Ankit,
The application is working and println is displaying unexpected result in console.
See my notes in original posting for what println is currently displaying in console.
I am opening url: http://localhost:8080/FitnessTracker/addMinutes.html without a problem.
I enter a number and click the button and it takes the number.
then it redirects you to the url: http://localhost:8080/FitnessTracker/addMoreMinutes.html
followed by writing the println to the console.
But the println the error, it should be writting both the println from addMinutes and the println from addMoreMinutes.
but it is only writing the println from addmoreMinutes, that's the issue.
Why is it skipping the println from the addMinutes method, that's what I'm trying to figure out.
Let me know your thoughts.
 
Ankit Garg
Sheriff
Posts: 9591
34
Android Google Web Toolkit Hibernate IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can you share your spring config and web.xml as well. I want to understand if you have mapped Spring to handle all *.html requests. If so, the first time you open addMinutes.html, it should redirect you to addMoreMinutes.html. Then when you enter a number and submit, it will go to addMoreMinutes method not addMinutes...
 
Joe McTigue
Ranch Hand
Posts: 71
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
 
Ankit Garg
Sheriff
Posts: 9591
34
Android Google Web Toolkit Hibernate IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Based on your config, when you first open http://localhost:8080/FitnessTracker/addMinutes.html, you should be redirected to http://localhost:8080/FitnessTracker/addMoreMinutes.html (unless I'm missing something). Then when you submit, the request will go to addMoreMinutes method and not addMinutes method. Can you check in the browser address bar that when you open http://localhost:8080/FitnessTracker/addMinutes.html you get redirected to http://localhost:8080/FitnessTracker/addMoreMinutes.html, only then you should get the form to enter minutes...
 
Joe McTigue
Ranch Hand
Posts: 71
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Ankit,

I figured out the issue, my code was correct, I had a corrupted jar file in my maven .m2 folder.
I deleted all my .m2 jars and rebuilt them, then tried it again and all works fine now.

Thank you for your time and effort.

Regards,
Joe
 
Ankit Garg
Sheriff
Posts: 9591
34
Android Google Web Toolkit Hibernate IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Happy to hear that, enjoy the learning
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!