根据请求“接受”标题,具有不可接受的特征的响应

时间:2016-03-22 08:17:58

标签: spring-mvc

我正在使用Spring MVC。尝试将POJO对象列表发送到jsp页面,但我在Web浏览器中收到以下行错误:

请帮帮我。

错误消息

  

HTTP状态406 -

     

此请求标识的资源只能生成   根据请求具有不可接受的特征的回复   “接受”标题。

代码快照:

1。控制器

@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;

}

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;
}

第3。链接从register.jsp

调用showUser.jsp

<a href="displayUsers.form">Show Users</a>

4。 showuser.jsp:

    <%@ 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>  &nbsp;/ &nbsp;  
                          <a href=""><font color="red">Delete</font></a>   
                    </td>
                 </tr>      
               </c:forEach>

            </table>

        </form>

    </body>
    </html>

5。调度员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>

1 个答案:

答案 0 :(得分:0)

只需删除注释&#39; @ ResponseBody&#39;来自Controller方法

@RequestMapping(value="displayUsers", method=RequestMethod.GET)
public ModelAndView showUsers(HttpServletRequest request){

  // code...

}