0

I have a basic jsp application and when I try to create a cookie, it won't find the library or have any idea what a "Cookie" is. Any ideas why?

<%--
  Created by IntelliJ IDEA.
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
  <head>
    <title>Login</title>
  </head>
  <body>
  <div>
    <div>
      <form method="post">
        <div>Username: </div>
        <input type="text" name="user"/>
          <%
              String user = request.getParameter("user");
              if (user != null) {
                  Cookie cookie = new Cookie();
                  response.addCookie(new Cookie("user", user));
                  response.sendRedirect("/main.jsp");
              }
          %>

      </form>
    </div>
  </div>
  </body>
</html>
Mocktheduck
  • 1,333
  • 1
  • 22
  • 43

1 Answers1

1

Just like with all other classes (except those in java.lang), you need to use the fully qualified name or add an import statement.

<%@ page import="javax.servlet.http.Cookie" %>
Community
  • 1
  • 1
Thilo
  • 257,207
  • 101
  • 511
  • 656