Vika7
@Vika7
вебист

HTTP Status 500 cannot be cast to?

Сообщество, необходима помощь!

Браузер выдает ошибку:

HTTP Status 500 - java.util.ArrayList cannot be cast to masters.User
________________________________________
type Exception report
message java.util.ArrayList cannot be cast to masters.User
description The server encountered an internal error that prevented it from fulfilling this request.
exception
java.lang.ClassCastException: java.util.ArrayList cannot be cast to masters.User
masters.masterservlet.MastersServlet.doGet(MastersServlet.java:52)
javax.servlet.http.HttpServlet.service(HttpServlet.java:620)
javax.servlet.http.HttpServlet.service(HttpServlet.java:727)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
note The full stack trace of the root cause is available in the Apache Tomcat/7.0.56 logs.
________________________________________
Apache Tomcat/7.0.56


Мой Код
в index.jsp:

<script>
stationList = [

<c:forEach items="${usersB}" var="userB">
       {"latlng":[<c:out value="${userB.barberlat}" />, <c:out value="${userB.barberlng}" />],
           name:"<c:out value="${userB.barbername}" />",
           url:"/MastersServlet?action=listUser&userId=<c:out value="${userB.barbername}"/>",
           address:"Dostyk str"},
        </c:forEach>
    ];
...
<script>


в Сервлете:

....
private static String INSERT_OR_EDITB = "user.jsp";
....
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        String forward = "";
        String action = request.getParameter("action");
else if (action.equalsIgnoreCase("listUser")) {
            forward = INSERT_OR_EDITB;
            String userId = request.getParameter("userId");
            User user = (User) dao.getAllUsersM(userId);
            request.setAttribute("user", user);


в DAO:

public List<User> getAllUsersM(String userId) {
        List<User> users = new ArrayList<User>();
        try {
            PreparedStatement preparedStatement = connection.prepareStatement("select * from master_table where barbername=?");
            preparedStatement.setString(1, userId);
            ResultSet rs = preparedStatement.executeQuery();
            while (rs.next()) {
               User user = new User();
               System.out.println(rs.getString("mastername"));
                user.setMastername(rs.getString("mastername"));
                user.setMasterlastname(rs.getString("masterlastname"));
                user.setMastersphone(rs.getString("mastersphone"));
                user.setMasteravatar(rs.getString("masteravatar"));
              /* user.setMasteregistration(rs.getDate("masterregistration"));*/
                users.add(user);
            }
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return users;
    }


в user.jsp

<body>
<table border=1 style="width: 100%">
    <thead>
    <tr>
        <th>name</th>
        <th>avatar</th>
        <th>lastname</th>
        <th>phone</th>

    </tr>
    </thead>
    <tbody>
    <c:forEach items="${users}" var="user">
        <tr style="cursor:pointer " onMouseOver="this.style.background='#FFCC33'"  onMouseOut="this.style.background='white'"
            onClick="window.open('MasterServlet?action=listUser&userId=<c:out value="${user.mastername}"/>','newwindow',
                    'width=600,height=650')">
            <td><c:out value="${user.mastername}" /></td>
            <td><c:out value="${user.masterlastname}" /></td>
            <td><c:out value="${user.mastersphone}" /></td>
            <td><c:out value="${user.masteravatar}" /></td>
            
        </tr>
    </c:forEach>
</tbody>
</table>
</body>
  • Вопрос задан
  • 94 просмотра
Решения вопроса 1
zagayevskiy
@zagayevskiy Куратор тега Java
Android developer at Yandex
user = (User) dao.getAllUsersM(userId);
Очевидно, что getAllUsersM возвращает список юзеров.
Ответ написан
Пригласить эксперта
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Похожие вопросы
22 нояб. 2024, в 22:26
3500 руб./за проект
22 нояб. 2024, в 21:47
3000 руб./за проект
22 нояб. 2024, в 21:44
50000 руб./за проект