1
Hello. I have a line error:
Cookie cookie = new Cookies(req.getCookies().getUsuarioLogado();
The complete method/class is this:
@WebServlet(urlPatterns = "/logout")
public class Logout extends HttpServlet {
protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
//String getCookies = req.getParameter(getCookies);
//String getUsuarioLogado = req.getParameter(getUsuarioLogado);
Cookie cookie = new Cookies(req.getCookies().getUsuarioLogado();
if(cookie!=null) {
cookie.setMaxAge(0);
resp.addCookie(cookie);
}
PrintWriter writer = resp.getWriter();
writer.println("<html><body>Logout efetuado</body></html>");
}
}
I am unable to solve the error. Does anyone know?
Thank you
But I kind of want to know why you’re wrong about the line I mentioned.
– André
@Thiagoferreira What was the error? You did not point. Type, I believe is the call attempt of the method: Cookie cookie = new Cookies(req.getCookies(). getUsuarioLog(); , not to mention that it is missing close the parentheses at the end of the line. But anyway you can’t do eq.getCookies(). getUsuarioLog() because getCookies returns an array of Cookies and not an object that has the getUsuarioLog method
– Bruno Viana
this error: Cannot invoke getUsuarioLog() on the array type Cookie[]
– André
closed the parentheses and continued the error.
– André
So is as I said... you cannot do getUsuarioLog() because a Cookie[] does not have this method. The correct way is to do as I put in the answer, you have to iterate the Array and make your logic to recover the user.
– Bruno Viana
I just put the parentheses in the right place and it worked right here.
– André