我想要做一些示例應用程序。但是,當我試圖顯示一個沒有任何內容的視圖時,我得到的輸出就像「請求的資源()不可用」。請糾正我在哪裏,我錯了..控制器類不爲彈簧加載
的WebContent/index.jsp的
<%
System.out.println("--inside index--");
response.sendRedirect("newUser.jav"); %>
的WebContent/WEB-INF/web.xml中
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" id="WebApp_ID" version="3.0">
<display-name>xHaiSpring</display-name>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
<welcome-file>index.htm</welcome-file>
<welcome-file>index.jsp</welcome-file>
<welcome-file>default.html</welcome-file>
<welcome-file>default.htm</welcome-file>
<welcome-file>default.jsp</welcome-file>
</welcome-file-list>
<servlet>
<servlet-name>dispatcher</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>dispatcher</servlet-name>
<url-pattern>*.jav</url-pattern>
</servlet-mapping>
</web-app>
的WebContent/WEB-INF /調度員的servlet .XML
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:p="http://www.springframework.org/schema/p"
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.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.0.xsd">
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver" id="viewResolver"
p:prefix="/JSP/" p:suffix=".jsp">
</bean>
</beans>
控制器文件
package com.mycontroller;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.ModelAndView;
@Controller
public class UserController{
@RequestMapping(value="/newUser", method=RequestMethod.GET)
public ModelAndView newUserForm()
{
System.out.println("inside controller");
return new ModelAndView("registerUser");
}
}
,我已經在的WebContent/JSP/A registerUser.jsp這是一個空白的jsp頁面
問題是什麼?爲什麼我沒有收到該控制器文件?
你能後所有的錯誤消息的? –
其實我的控制檯正在打印「--inside index--」。並沒有顯示其他錯誤。瀏覽器顯示消息「請求的資源不可用」 –
難道你的DispatcherServlet被映射到'* .jav',但你的Controller映射到'/ newUser'嗎? – ftr