0

I am trying to reference a new .jsp in my WEB-INF/pages folder, but continue to get a server error (specifically 500). I am new to Spring so am unsure exactly where my problem is so I have provided pieces of the code below and can provide more details if needed.

My ViewResolver is:

   <bean class="org.springframework.web.servlet.view.ContentNegotiatingViewResolver">
   <property name="contentNegotiationManager" ref="contentNegotiationManager"/>
   <property name="viewResolvers">
            <list>
                <bean 
   class="org.springframework.web.servlet.view.UrlBasedViewResolver">
                    <property name="viewClass"
                              value="org.springframework.web.servlet.view.JstlView" />
                    <property name="prefix" value="/WEB-INF/pages/" />
                    <property name="suffix" value=".jsp" />
                </bean>
            </list>
        </property>
        <property name="defaultViews">
            <list>
                <bean class="org.springframework.web.servlet.view.json.MappingJackson2JsonView">
                    <property name="prefixJson" value="true" />
                </bean>
            </list>
        </property>
   </bean>

while my Controller is:

@Controller
@RequestMapping("/nav")
public class NavigationController {
    private static Logger logger = LoggerFactory.getLogger(NavigationController.class);

    @Autowired
    private NavigationService navigationService;

    @Autowired
    private UserService userService;

    @RequestMapping("/home")
    public ModelAndView home() {
        ModelAndView modelAndView = new ModelAndView("index");
        modelAndView.addObject("testimonials", navigationService.getTop5Testimonials());
        return modelAndView;
    }

    @RequestMapping(value = "/page", method = RequestMethod.GET)
    public ModelAndView newpage() {
        ModelAndView modelAndView = new ModelAndView("about2");
        return modelAndView;
    }

My Dispatcher Servlet is

<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context"
       xsi:schemaLocation="
        http://www.springframework.org/schema/beans     http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
        http://www.springframework.org/schema/context   http://www.springframework.org/schema/context/spring-context-3.1.xsd">
    <context:component-scan base-package="com.mazefire.controller"/>
</beans>

and the web.xml is

<web-app xmlns="http://java.sun.com/xml/ns/javaee"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         version="3.0"
         xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
        http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd">
    <display-name>MazeFire</display-name>
    <description>MazeFire Digital Maze Games</description>

    <welcome-file-list>
        <welcome-file>/nav/home.do</welcome-file>
    </welcome-file-list>

    <servlet-mapping>
        <servlet-name>MazeFireDispatcher</servlet-name>
        <url-pattern>*.do</url-pattern>
    </servlet-mapping>

Things worked fine referencing the homepage (index.jsp) using

<a href="<c:url value="/nav/home.do"/>"

but when I try to reference the new page (about2.jsp) the website doesn't load and I get the error.

<a href="<c:url value="/nav/page/about2.do"/>"

I feel the problem is in the syntax for /page request, but would appreciate any help in figuring out what is wrong. If any other information is needed, please let me know.

Update: Logs show:

27-Jul-2017 11:13:51.283 INFO [RMI TCP Connection(2)-127.0.0.1] org.apache.catalina.core.ApplicationContext.log No Spring WebApplicationInitializer types detected on classpath
27-Jul-2017 11:13:56.603 INFO [RMI TCP Connection(2)-127.0.0.1] org.apache.catalina.core.ApplicationContext.log Initializing Spring root WebApplicationContext
27-Jul-2017 11:15:25.121 INFO [RMI TCP Connection(2)-127.0.0.1] org.apache.catalina.core.ApplicationContext.log Initializing Spring FrameworkServlet 'MazeFireDispatcher'
27-Jul-2017 11:16:46.653 SEVERE [RMI TCP Connection(2)-127.0.0.1] org.apache.catalina.core.ApplicationContext.log StandardWrapper.Throwable
 org.springframework.transaction.CannotCreateTransactionException: Could not open JPA EntityManager for transaction; nested exception is org.hibernate.exception.GenericJDBCException: Could not open connection
Caused by: org.hibernate.exception.GenericJDBCException: Could not open connection
Caused by: java.sql.SQLException: Cannot create PoolableConnectionFactory (Communications link failure
The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server.)
Caused by: com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure
The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server.
Caused by: java.net.ConnectException: Operation timed out (Connection timed out)
27-Jul-2017 11:16:46.654 SEVERE [RMI TCP Connection(2)-127.0.0.1] org.apache.catalina.core.StandardContext.loadOnStartup Servlet [MazeFireDispatcher] in web application [] threw load() exception
 java.net.ConnectException: Operation timed out (Connection timed out)
27-Jul-2017 11:16:46.695 INFO [RMI TCP Connection(8)-127.0.0.1] org.apache.catalina.core.ApplicationContext.log Closing Spring root WebApplicationContext
27-Jul-2017 11:16:49.653 INFO [RMI TCP Connection(8)-127.0.0.1] org.apache.catalina.core.ApplicationContext.log No Spring WebApplicationInitializer types detected on classpath
27-Jul-2017 11:16:54.980 INFO [RMI TCP Connection(8)-127.0.0.1] org.apache.catalina.core.ApplicationContext.log Initializing Spring root WebApplicationContext
27-Jul-2017 11:18:18.151 INFO [RMI TCP Connection(8)-127.0.0.1] org.apache.catalina.core.ApplicationContext.log Initializing Spring FrameworkServlet 'MazeFireDispatcher'
27-Jul-2017 11:19:39.991 SEVERE [RMI TCP Connection(8)-127.0.0.1] org.apache.catalina.core.ApplicationContext.log StandardWrapper.Throwable
27-Jul-2017 11:19:39.991 SEVERE [RMI TCP Connection(8)-127.0.0.1] org.apache.catalina.core.StandardContext.loadOnStartup Servlet [MazeFireDispatcher] in web application [] threw load() exception
27-Jul-2017 11:19:42.718 INFO [http-nio-8080-exec-1] org.apache.catalina.core.ApplicationContext.log Initializing Spring FrameworkServlet 'MazeFireDispatcher'
27-Jul-2017 11:21:01.341 SEVERE [http-nio-8080-exec-1] org.apache.catalina.core.ApplicationContext.log StandardWrapper.Throwable
27-Jul-2017 11:21:01.341 SEVERE [http-nio-8080-exec-1] org.apache.catalina.core.StandardWrapperValve.invoke Allocate exception for servlet [MazeFireDispatcher]
27-Jul-2017 11:21:01.342 INFO [http-nio-8080-exec-9] org.apache.catalina.core.ApplicationContext.log Initializing Spring FrameworkServlet 'MazeFireDispatcher'
27-Jul-2017 11:22:23.009 SEVERE [http-nio-8080-exec-9] org.apache.catalina.core.ApplicationContext.log StandardWrapper.Throwable
27-Jul-2017 11:22:23.009 SEVERE [http-nio-8080-exec-9] org.apache.catalina.core.StandardWrapperValve.invoke Allocate exception for servlet [MazeFireDispatcher]
JKJ
  • 1
  • 3
  • try `/nav/page.do`, the URL maps to a method not to the location of the file – tima Jul 24 '17 at 00:48
  • Thanks @tima but it is now loading an internal error page instead of the about2.jsp even though the URL is referencing correctly as (http://mazepilot.com/nav/about.do). I am building off someone else's code and most other pages are using the GET method with RequestParam so not sure if there are conflicts with what I am trying to add as mentioned in my post. – JKJ Jul 26 '17 at 17:00
  • i'm not sure what the problem is but `/nav/page.do` should be the correct URL. Maybe check the logs to see why the internal error page shows up. – tima Jul 27 '17 at 01:14
  • I've added the logs running a local environment using Tomcat on IntelliJ IDEA. Unfortunately I'm too new to be able to make sense of them and am not 100% sure if the errors shown here match with whatever error is happening on the live website (sort of figuring all of this out on the fly). I have the detailed logs saved as PDF's if helpful. – JKJ Jul 27 '17 at 16:03

1 Answers1

0

You are getting 500 because of Communications link failure between your data base and your application

 org.hibernate.exception.GenericJDBCException: Could not open connection
    Caused by: org.hibernate.exception.GenericJDBCException: Could not open connection
    Caused by: java.sql.SQLException: Cannot create PoolableConnectionFactory (Communications link failure
    The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server.)
    Caused by: com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure
    The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server.
    Caused by: java.net.ConnectException: Operation timed out (Connection timed out)
    27-Jul-2017 11:16:46.654 SEVERE [RMI TCP Connection(2)-127.0.0.1] org.apache.catalina.core.StandardContext.loadOnStartup Servlet [MazeFireDispatcher] in web application [] threw load() exception
     java.net.ConnectException: Operation timed out (Connection timed out)

Make sure that your application have network access to your database (and the firewall isn't blocking ports to your database).

Also here is some helpful info about it.

Bhushan Uniyal
  • 5,575
  • 2
  • 22
  • 45