0
我想在我的WEB-INF/pages文件夾中引用一個新的.jsp,但繼續得到服務器錯誤(特別是500)。我是Spring的新手,所以我不清楚我的問題在哪裏,所以我已經提供了下面的代碼片段,如果需要可以提供更多的細節。服務器錯誤使用@RequestMapping獲取.jsp加載
我的ViewResolver是:
<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>
,而我的控制器是:
@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;
}
我的調度員Servlet是
<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>
和web.xml中是
<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>
件
事情的來龍去脈精細參考使用
<a href="<c:url value="/nav/home.do"/>"
首頁(index.jsp)之後,但是當我試圖引用新的頁面(about2.jsp)的網站沒有加載,我得到的錯誤。
<a href="<c:url value="/nav/page/about2.do"/>"
我覺得這個問題是在語法/頁面請求,但希望在搞清楚什麼是錯的任何幫助。如果需要其他信息,請告訴我。
更新:日誌顯示:
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]
嘗試'/ nav/page.do',URL映射到的方法不是文件的位置 – tima
謝謝@tima,但它現在加載了一個內部錯誤頁面而不是about2.jsp,即使URL是正確引用(http://mazepilot.com/nav/about.do)。我構建了別人的代碼,其他大多數頁面都使用GET方法和RequestParam,所以不確定是否與我在文章中提到的添加內容有衝突。 – JKJ
我不確定問題是什麼,但'/ nav/page.do'應該是正確的URL。也許檢查日誌以瞭解內部錯誤頁面顯示的原因。 – tima