HttpSession java

0

I'm trying to implement HttpSession in my code but this is giving an error in

  

request.getsession () that says    The method getSession () is undefined for the HttpRequest type

My code

import java.io.IOException;
import java.util.List;

import javax.faces.application.FacesMessage;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
import javax.faces.context.FacesContext;
import javax.servlet.http.HttpSession;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpRequest;

import DAO.LoginDao;
import Impl.LoginimplDAO;
import classhiber.Utilizador;
@ManagedBean(name = "Login")
@SessionScoped
public class Login {
    @Autowired
    public String user;

    private  HttpRequest request;
    @Autowired
    public String pwd;
    @Autowired
    private LoginDao log;

    public Login()
    {
        log = new LoginimplDAO();
    }
    public String getUser() {
        return user;
    }

    public void setUser(String user) {
        this.user = user;
    }

    public String getPwd() {
        return pwd;
    }

    public void setPwd(String pwd) {
        this.pwd = pwd;
    }

    public void red () throws IOException
    {
        FacesContext context = FacesContext.getCurrentInstance();

        List<Utilizador> result = log.findlogin(getUser(), getPwd());
        if(result.isEmpty())
        {
            context.addMessage(null, new FacesMessage("Erro",  "Falhado") );

        }
        else
        {
            //Contar objectos da lista
            System.out.println(result.size());
            HttpSession sessao = request.getSession();  
            context.addMessage(null, new FacesMessage("Sucesso",  "Login") );

        }
    //  FacesContext.getCurrentInstance().getExternalContext().redirect(  
        //            FacesContext.getCurrentInstance().  
        //      getExternalContext().getRequestContextPath() + "/registar.xhtml");
    }
}

Does anyone know what might be causing this error?

Thank you.

    
asked by anonymous 04.09.2015 / 17:17

1 answer

2

Try using:

HttpServletRequest req = (HttpServletRequest)FacesContext.getCurrentInstance()
                                                         .getExternalContext()
                                                         .getRequest();

HttpServletResponse res = (HttpServletResponse)FacesContext.getCurrentInstance()
                                                           .getExternalContext()
                                                           .getResponse();
    
04.09.2015 / 17:55