0

我只是在尝试使用 jsp 并希望在表格中显示所有条目,

我的 servlet 是这个

        package UserPass;

        import data.UserPassDb;
        import java.io.IOException;
        import javax.servlet.RequestDispatcher;
        import javax.servlet.ServletException;
        import javax.servlet.http.HttpServlet;
        import javax.servlet.http.HttpServletRequest;
        import javax.servlet.http.HttpServletResponse;

        /**
        *
        * @author One
        */
        public class UserPassController extends HttpServlet {


            @Override
            protected void doGet(HttpServletRequest request, HttpServletResponse response)
                    throws ServletException, IOException {

                doPost(request,response);
            }


            @Override
            protected void doPost(HttpServletRequest request, HttpServletResponse response)
                    throws ServletException, IOException {

                request.setAttribute("users", UserPassDb.selectAllUser());

                String forward = "/me/testpage.jsp";
                RequestDispatcher view = request.getRequestDispatcher(forward);
                view.forward(request, response);

            }



        }

和我的测试页

     <a href="<c:url value='/test/TestServlet'/>">
      refresh
      </a><br><br>


    <c:forEach var="user" items="${users}">

        <c:out value="${user.user_name}"/> 

    </c:forEach>

谢谢大家..我正在做教程并试图自己解决那些初学者问题,但一再失败:(

4

2 回答 2

0

在您的类中添加注释@WebServlet("/TestServlet")或将您的 servlet 添加到web.xml.

尝试从浏览器访问 servlet,并检查是否可以访问 servlet。(可能带有网址http://localhost:8080/Test/TestServlet:)

于 2012-09-13T15:03:41.793 回答
0

我不知道为什么到目前为止,但就是这样

     <a href="<c:url value='/TestServlet'/>" >
于 2012-09-13T16:25:40.877 回答