我只是在尝试使用 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>
谢谢大家..我正在做教程并试图自己解决那些初学者问题,但一再失败:(