我有3个链接,教师,学生和员工。当点击任何链接时,我希望它们转到Selection servlet,servlet将检查选择了哪个链接。之后,它会将其转发到所需的JSP页面。我不知道该怎么做。
到目前为止,这是我的代码:
JSP文件:
<!DOCTYPE html>
<html>
<head>
<title>Selection</title>
</head>
<body>
<h2>Please Choose One</h2>
<a name="select" value= "Teacher" href="UserSelection"> Teacher </a> <!-- Not sure if I need name and value -->
<a name="select" href="UserSelection"> Student </a>
<a name="select" href="UserSelection"> Employee </a>
</body>
</html>
选择Servlet:
@WebServlet("/UserSelection")
public class UserSelection extends HttpServlet
{
private static final long serialVersionUID = 1L;
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
{
}
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
{
String selection = request.getParameter("select");
if("Teacher".equals(selection))
{
System.out.println("Teacher");
}
}
}