2017-07-24 5 views
0

Je suis en train de faire référence à un nouveau .jsp dans mon dossier WEB-INF/pages, mais continuer à obtenir une erreur de serveur (en particulier 500). Je suis nouveau au printemps donc je ne sais pas exactement où mon problème est si j'ai fourni des pièces du code ci-dessous et peut fournir plus de détails si nécessaire.Erreur du serveur à l'aide @RequestMapping pour obtenir .jsp à charger

Mon ViewResolver est:

<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> 

alors que mon contrôleur est:

@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; 
    } 

Mon Dispatcher Servlet est

<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> 

et web.xml est

<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> 

Les choses ont fonctionné très bien référence à la page d'accueil (index.jsp) en utilisant

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

mais lorsque je tente de faire référence à la nouvelle page (about2.jsp) le site ne se charge pas et je reçois l'erreur.

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

je me sens le problème est dans la syntaxe demande/page, mais apprécierait toute aide à déterminer ce qui est faux. Si d'autres informations sont nécessaires, s'il vous plaît faites le moi savoir.

Mise à jour: Afficher les journaux:

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] 
+0

essayer '/ nav/page.do', les cartes d'URL à une méthode pas à l'emplacement du fichier – tima

+0

Merci @tima mais il se charge maintenant une page d'erreur interne au lieu de l'about2.jsp même si l'URL est référencer correctement comme (http://mazepilot.com/nav/about.do). Je construis le code de quelqu'un d'autre et la plupart des autres pages utilisent la méthode GET avec RequestParam donc je ne sais pas s'il y a des conflits avec ce que j'essaie d'ajouter comme mentionné dans mon post. – JKJ

+0

Je ne sais pas quel est le problème mais '/ nav/page.do' devrait être l'URL correcte. Peut-être vérifier les journaux pour voir pourquoi la page d'erreur interne apparaît. – tima

Répondre

0

Vous obtenez 500 en raison de la liaison de communication non entre votre base de données et votre 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) 

Assurez-vous que votre application a accès au réseau à votre base de données (et le pare-feu ne bloque pas les ports de votre base de données).

également here quelques informations utiles à ce sujet.