fatoma fatoma -4 years ago 86
Java Question

jsp/servlet Pages redirection

i have two page JSP

profile.jsp
and
comprofile.jsp

I will make a direction towards page
profile.jsp
if my attribut booleen
etat
in my table
etat=1
redirection
profile.jsp

else if
etat=0
redirection
comprofile.jsp


My code



protected void processRequest(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html;charset=UTF-8");
HttpSession Session = request.getSession();
// response.getWriter().print("welcome" + Session.getAttribute("idoperateur"));
// Object getAttribut(int idoperateur);
String idoperateur = (String)Session.getAttribute("idoperateur");
int etat;
try {
dbcon= new javaConnectDB();
conn=dbcon.setConnection();
stmt=conn.createStatement();
query="select * from operateur where idoperateur='"+idoperateur+"' ";
res=dbcon.getResult(query, conn);
etat=res.getInt(6);
while(res.next()){
etat=res.getInt(6);
lst.add(res.getString("idoperateur"));
lst.add(res.getString("nom_o"));
lst.add(res.getString("prenom_o"));
//lst.add(res.getString("password"));
}
if(etat==0){
request.setAttribute("data", lst);
RequestDispatcher rd= request.getRequestDispatcher("profile.jsp");
rd.forward(request, response);
lst.clear();

res.close();
}
}
catch(Exception e){
System.out.println();
}
}





but it did not work

Answer Source

your etat variable's scope is restricted to while{} loop alone..... then at your if condition etat will not be resolved to a variable

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download