首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > JAVA > Java Web开发 >

spring的MVC,该怎么解决

2012-01-13 
spring的MVC一个超级简单的mvc,出了超级郁闷的问题,jsp文件运行不报错,就是没任何显示.do文件运行完java程

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 MVC</title>

  </head>
  
  <body>
  <center>


  <h1>
  Hello,${user }!
  </h1>
  </center>
  </body>
</html>

运行http://127.0.0.1/webTest/hello.do?user=aa的效果

[解决办法]
就是jsp有问题 你把${user}去掉试一下
[解决办法]
看看标签里 有没有全角空格
[解决办法]
[code=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 MVC </title>

</head>

<body>
  <center>
  <h1>
  Hello,${user }!
  </h1>
  </center>
</body>
</html>
[/code]
看不清重新贴一下
[解决办法]

XML code
<%@ 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 MVC </title>  </head>   <body>    <center>    <h1>    Hello,${user }!    </h1>    </center>  </body></html>
[解决办法]
你没加 标签<%@ taglib uri="/WEB-INF/tld/c.tld" prefix="c"%>
[解决办法]
${user }要引进<%@ taglib uri="/WEB-INF/tld/c.tld" prefix="c"%>的

热点排行