spring的MVC
一个超级简单的mvc,出了超级郁闷的问题,
jsp文件运行不报错,就是没任何显示
.do文件运行完java程序就问你是不是下载
---HelloController.java--
Java code
package test002;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.Controller;
public class HelloController implements Controller
{
private String viewPage;
public void setViewPage(String viewPage)
{
this.viewPage=viewPage;
}
public ModelAndView handleRequest(HttpServletRequest request,
HttpServletResponse response) throws Exception
{
System.out.println("**************");
String user=request.getParameter("user");
this.setViewPage("hello");
ModelAndView mav=new ModelAndView(viewPage,"user",user);
System.out.println(user+"------------");
return mav;
}
}
--web.xml---
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5"
xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
<welcome-file-list>
<welcome-file>
index.jsp
</welcome-file>
</welcome-file-list>
<servlet>
<servlet-name>
dispatcherServlet
</servlet-name>
<servlet-class>
org.springframework.web.servlet.DispatcherServlet
</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>\WEB-INF\spring\mvc-config.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>dispatcherServlet</servlet-name>
<url-pattern>*.do</url-pattern>
</servlet-mapping>
</web-app>
--mvc-config.xml--
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN"
"http://www.springframework.org/dtd/spring-beans.dtd">
<!--
<beans
xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.0.xsd">
-->
<beans>
<bean id="viewResolver"
class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/WEB-INF/jsp/" />
<property name="suffix" value=".jsp" />
</bean>
<bean name="/hello.do"
class="test002.HelloController">
<property name="viewPage" value="hello"/>
</bean>
</beans>
--hello.jsp--
<%@ page language="java" import="java.util.*"
contentType="texst/html;charset=utf-8"
pageEncoding="utf-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>First Spring