2013-05-06 53 views
-1

我正在尝试一些春季样本的CRUD.Now我能够成功地将数据保存在数据库中,但是当我尝试通过jsp显示它时,我无法这样做。 ..My春天控制器类是如下错误,同时从弹簧控制器类传递数据到jsp

CController.java

@Controller 
public class CController{ 

    private UserDAO1 userDAO; 

    @Autowired @Qualifier("myUserDAO") 
    private UserDAOImpl1 myUserDAO; 

    @RequestMapping(value = "/frm4/add", method = RequestMethod.POST) 
    public ModelAndView add(@ModelAttribute("add") User1 user,HttpServletRequest 
      request,HttpServletResponse response) throws Exception { 
     System.out.println("hai"); 

     userDAO.saveUser(user); 

     return new ModelAndView("redirect:list.htm"); 
    } 

    @RequestMapping(params = "/frm/delete", method = RequestMethod.POST) 
    @Transactional 
    public ModelAndView delete(@ModelAttribute("delete") User1 user,HttpServletRequest 
      request,HttpServletResponse response) throws Exception { 
      userDAO.deleteUser(user); 
      return new ModelAndView("redirect:list.htm"); 
    } 


    @RequestMapping(params = "/frm/find", method = RequestMethod.POST) 
    @Transactional 
    public ModelAndView find(@ModelAttribute("find") User1 user,HttpServletRequest 
      request,HttpServletResponse response) throws Exception { 
        userDAO.findUser(user); 
         return new ModelAndView("redirect:list.htm"); 
    } 


    @RequestMapping(params = "/frm/update", method = RequestMethod.POST) 
    @Transactional 
    public ModelAndView update(@ModelAttribute("update") User1 user,HttpServletRequest 
       request,HttpServletResponse response) throws Exception { 
        userDAO.updateUser(user); 
         return new ModelAndView("redirect:list.htm"); 
    } 

    public ModelAndView list(HttpServletRequest request, 
     HttpServletResponse response) throws Exception { 


     ModelMap modelMap = new ModelMap(); 
     modelMap.addAttribute("userList", userDAO.listUser()); 
     modelMap.addAttribute("user", new User1()); 
     return new ModelAndView("list", modelMap); 
    } 
} 

和我的JSP文件如下

的List.jsp

<html> 
<head> 
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"> 
<title>Insert title here</title> 
</head> 
<body> 
    <form:form method="POST"> 
    <table> 
    <tr> 
     <td width="50">Id</td> 
     <td width="150">First Name</td> 
     <td width="150">Last Name</td> 
     <td width="100">Money</td> 
     <td width="50">Currency</td> 
    </tr> 
    <c:forEach items="${list}" var="person"> 
    <tr> 
    <td><c:out value="${person.id}" /></td> 
    <td><c:out value="${person.name}" /></td> 
    <td><c:out value="${person.password}" /></td> 
    <td><c:out value="${person.gender}" /></td> 
    <td><c:out value="${person.country}" /></td> 
    </tr> 
    </c:forEach> 
    </table> 
</form:form> 
</body> 
</html> 

和我的控制器的配置文件如下

CController-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:aop="http://www.springframework.org/schema/aop" 
xmlns:tx="http://www.springframework.org/schema/tx" 
xmlns:context="http://www.springframework.org/schema/context" 
xmlns:util="http://www.springframework.org/schema/util" 
xmlns:mvc="http://www.springframework.org/schema/mvc" 
xsi:schemaLocation="http://www.springframework.org/schema/beans 
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd 
http://www.springframework.org/schema/jdbc http://www.springframework.org/schema 
    /jdbc/spring-jdbc-3.0.xsd 
http://www.springframework.org/schema/tx http://www.springframework.org/schema 
    /tx/spring-tx-3.0.xsd 
http://www.springframework.org/schema/util http://www.springframework.org/schema 
     /util/spring-util-3.0.xsd 
http://www.springframework.org/schema/mvc http://www.springframework.org/schema 
     /mvc/spring-mvc-3.0.xsd 
http://www.springframework.org/schema/context http://www.springframework.org/schema 
     /context/spring-context-3.0.xsd"> 

<mvc:annotation-driven /> 
<context:annotation-config/> 


<bean 
class="org.springframework.web.servlet.mvc.support.ControllerClassNameHandlerMapping"/> 


<bean id="urlMapping" 
    class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping"> 
    <property name="mappings"> 
     <props> 
      <prop key="index.htm">indexController</prop> 


     </props> 
    </property> 
</bean> 



<bean id="viewResolver" 
     class="org.springframework.web.servlet.view.InternalResourceViewResolver" 
     p:prefix="/WEB-INF/jsp/" 
     p:suffix=".jsp" /> 


<bean name="cController.do" class="project4.CController" > 
    <property name="userDAO" ref="myUserDAO"/> 

</bean> 


<bean name="indexController" 
    class="org.springframework.web.servlet.mvc.ParameterizableViewController" 
     p:viewName="index" /> 

</beans> 

我有三个XML文件一个经理级别的,另一个是为道,另一个是应用程序上下文。以上是经理水平XML

当我尝试显示在jsp中的数据,下面的错误发生

HTTP Status 404 - 

-------------------------------------------------------------------------------- 

type Status report 

message 

description The requested resource() is not available. 

和我收到的网址为

http://localhost:8080/Spring/frm4/list.htm 

当实际的URL我应该得到的是

http://localhost:8080/Spring/list.htm 

FRM4是我的其他JSP形式,我将数据传输到控制器类。

有人可以帮助PLZ

回答

0

我通过手动添加

<mvc:default-servlet-handler /> 

我的Spring配置文件固定它。

0

您可以将此行
return new ModelAndView("redirect:list.htm");
更改为
return new ModelAndView("redirect:/list.htm");
这将解决这个问题。

+0

thnx for ur help – Ezhil 2013-05-07 07:42:36

相关问题