1 回答
TA贡献1880条经验 获得超4个赞
你的实现在这里很遥远。您需要执行以下操作。您可以使用 JSP EL 访问请求属性:
<p>Event Count is ${eventCount}</p>
<p>Affiliate Count is ${affiliateCount}</p>
<p>User Name is ${user.forename} ${user.surname}</p>
小服务程序
@WebServlet("/organizer")
public class UserLogin extends HttpServlet {
protected void doGet(HttpServletRequest request,
HttpServletResponse response)
throws ServletException, IOException {
doPost(request, response);
}
@SuppressWarnings("Duplicates")
protected void doPost(HttpServletRequest request,
HttpServletResponse response)
throws ServletException, IOException {
String email = request.getParameter("email");
String password = request.getParameter("password");
User user = getUsert(emil password)
if(user != null){
request.setAttributes("eventCount", getEventsCount(email, password));
request.setAttributes("affiliateCount", getAffiliatesCount(email,password));
request.getRequestDispatcher("/dashboard.jsp").forward(request, response);
}else{
request.setAttribute("failedLogin", true);
request.getRequestDispatcher("/login.jsp").forward(request, response);
}
}
protected User getUser(String email String password){}
User user = null; //create a class user with 3 fields
// Query
if(rs.next()){
user = new User(rs.getInt("id"),
rs.getString("firstname"),
rs.getString("lastname"))
}
return user;
}
protected int getEventsCount(String email, String password)
throws ServletException, IOException {
// query and return result
return count;
}
protected void getAffiliatesCount(String email, String password)
throws ServletException, IOException {
// query and return result
return count;
}
}
添加回答
举报