我正在为 CRUD 尝试一些 spring 示例。现在我能够成功地将数据保存在数据库中,但是当我尝试通过 jsp 显示它时,我无法这样做......我的 spring 控制器类如下
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文件如下
列表.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 文件,一个用于经理级别,另一个用于 dao,另一个是应用程序上下文。上面是经理级别 xml
当我尝试在jsp中显示数据时,出现以下错误
HTTP Status 404 -
--------------------------------------------------------------------------------
type Status report
message
description The requested resource () is not available.
我得到的网址为
http://localhost:8080/Spring/frm4/list.htm
当我应该得到的实际网址是
http://localhost:8080/Spring/list.htm
frm4 是我将数据传输到控制器类的另一个 jsp 表单。
有人可以帮忙吗?