0

I have 3 links, Teacher, Student, and Employees. When clicked on any links, I want them to go to the Selection servlet and the servlet will check what link was selected. After that, it will forward it to the desired JSP page. I am not sure how to do that.

Here is my code so far:

JSP File:

<!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>

Selection 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");
        }

    }

}
Nasim Ahmed
  • 235
  • 2
  • 17
  • Have a look at this and it should give you an idea. Why not use a form? http://stackoverflow.com/questions/4971877/how-to-transfer-data-from-jsp-to-servlet-when-submitting-html-form and http://stackoverflow.com/questions/6791238/send-post-request-on-click-of-href-in-jsp – riddle_me_this Oct 23 '16 at 03:21
  • @bphilipnyc Thanks – Nasim Ahmed Oct 23 '16 at 12:55

0 Answers0