Spring mvc 根据请求,具有不可接受特征的响应”;接受;标题
我正在使用SpringMVC。试图将POJO对象列表发送到jsp页面,但我在web浏览器中遇到以下行错误: 请帮帮我 错误消息 HTTP状态406- 此请求标识的资源只能生成 根据请求,具有不可接受特征的响应 “接受”标题 代码快照: 1。控制器Spring mvc 根据请求,具有不可接受特征的响应”;接受;标题,spring-mvc,Spring Mvc,我正在使用SpringMVC。试图将POJO对象列表发送到jsp页面,但我在web浏览器中遇到以下行错误: 请帮帮我 错误消息 HTTP状态406- 此请求标识的资源只能生成 根据请求,具有不可接受特征的响应 “接受”标题 代码快照: 1。控制器 @RequestMapping(value="displayUsers", method=RequestMethod.GET) public @ResponseBody ModelAndView showUsers(HttpServletRequest
@RequestMapping(value="displayUsers", method=RequestMethod.GET)
public @ResponseBody ModelAndView showUsers(HttpServletRequest request){
ModelAndView objModel=new ModelAndView();
UserDAO objUserDAO=DAOFactory.getInstanceOfUser();
// fetching list of all the users
List<User> listOfUser=objUserDAO.listOfUser();
objModel.addObject("listOfUser", listOfUser );
objModel.setViewName("showuser");
return objModel;
}
@RequestMapping(value=“displayUsers”,method=RequestMethod.GET)
public@ResponseBody model和view showUsers(HttpServletRequest){
ModelAndView objModel=新ModelAndView();
UserDAO objUserDAO=DAOFactory.getInstanceFuser();
//正在获取所有用户的列表
List listOfUser=objUserDAO.listOfUser();
addObject(“ListoUser”,ListoUser);
objModel.setViewName(“showuser”);
返回objModel;
}
2。用户DAO:
public List<User> listOfUser(){
SessionFactory factory=HibernateUtils.getInstance();
Session session=factory.openSession();
String hqlQuery="From User u";
Query query=session.createQuery(hqlQuery);
List<User> list=query.list();
return list;
}
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<head>
<%@ include file="genericinclude.jsp"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>
</head>
<body>
<h2 align="center"><u>User List</u></h2>
<form name="showUserPage" method="post">
<table align="center" border="0">
<c:forEach var="userList" items="${listOfUser}">
<tr>
<td>${userList.userId }</td>
<td>${userList.firstName }</td>
<td>${userList.lastName}</td>
<td>${userList.userGender }</td>
<td>${userList.roll }</td>
<td>${userList.userMobile1 }</td>
<td>${userList.userMobile2 }</td>
<td>${userList.userEmail }</td>
<td> <a href="">Edit</a> /
<a href=""><font color="red">Delete</font></a>
</td>
</tr>
</c:forEach>
</table>
</form>
</body>
</html>
public List listOfUser(){
SessionFactory=HibernateUtils.getInstance();
Session Session=factory.openSession();
字符串hqlQuery=“来自用户u”;
Query Query=session.createQuery(hqlQuery);
List=query.List();
退货清单;
}
3。从register.jsp调用showUser.jsp的链接
4。showuser.jsp:
public List<User> listOfUser(){
SessionFactory factory=HibernateUtils.getInstance();
Session session=factory.openSession();
String hqlQuery="From User u";
Query query=session.createQuery(hqlQuery);
List<User> list=query.list();
return list;
}
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<head>
<%@ include file="genericinclude.jsp"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>
</head>
<body>
<h2 align="center"><u>User List</u></h2>
<form name="showUserPage" method="post">
<table align="center" border="0">
<c:forEach var="userList" items="${listOfUser}">
<tr>
<td>${userList.userId }</td>
<td>${userList.firstName }</td>
<td>${userList.lastName}</td>
<td>${userList.userGender }</td>
<td>${userList.roll }</td>
<td>${userList.userMobile1 }</td>
<td>${userList.userMobile2 }</td>
<td>${userList.userEmail }</td>
<td> <a href="">Edit</a> /
<a href=""><font color="red">Delete</font></a>
</td>
</tr>
</c:forEach>
</table>
</form>
</body>
</html>
用户列表
${userList.userId}
${userList.firstName}
${userList.lastName}
${userList.userGender}
${userList.roll}
${userList.userMobile1}
${userList.userMobile2}
${userList.userEmail}
/
5。dispatcher servlet.xml
<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"
xmlns:util="http://www.springframework.org/schema/util"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/util
http://www.springframework.org/schema/util/spring-util.xsd">
<context:component-scan base-package="com.marse.*"></context:component-scan>
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver" id="jspViewResolver">
<property name="viewClass" value="org.springframework.web.servlet.view.JstlView"></property>
<property name="prefix" value="/"></property>
<property name="suffix" value=".jsp"></property>
</bean>
</beans>
只需从控制器方法中删除注释“@ResponseBody”
@RequestMapping(value="displayUsers", method=RequestMethod.GET)
public ModelAndView showUsers(HttpServletRequest request){
// code...
}