我有一个没有框架的 java 应用程序。它由用于视图的 jsp 文件和用于业务逻辑的 servlet 组成。我必须将用户会话设置为带有 firstName 参数的 servlet。在 jsp 文件中,我需要检查我的 firstName 参数是否有值。如果设置了firstName参数,我需要在jsp文件中显示一些html。如果没有设置,我需要在jsp文件中显示不同的html。
Servlet.java:
HttpSession session = request.getSession();
session.setAttribute("firstName", customer.getFristName());
String url = "/index.jsp";
RequestDispatcher dispatcher = getServletContext().getRequestDispatcher(url);
dispatcher.forward(request, response);
header.jsp:
// Between the <p> tags bellow I need to put some HTML with the following rules
// If firstName exist: Hello ${firstName} <a href="logout.jsp">Log out</a>
// Else: <a href="login.jsp">Login</a> or <a href="register.jsp">Register</a>
<p class="credentials" id="cr"></p>
最好的方法是什么?
更新:
这是我在 JSTL 上找到的一个很棒的教程,以防万一有人需要它: http ://www.tutorialspoint.com/jsp/jsp_standard_tag_library.htm