GRazie per la tua risposta ...scusami se non ho risposto prima ... ma ieri sn stato tutto il giorno impegnato con un altro progetto ....
stamattina ho trovato a fare alcune modfica ma niente sempre stesso problema
iquesto è il codice della servlet:
codice:
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package servlet;
import java.io.IOException;
import java.io.PrintWriter;
import javax.ejb.EJB;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import model.Admin;
import model.Cameriere;
import model.Cliente;
import model.Cuoco;
import server.GestioneLoginLocal;
/**
*
* @author orphen
*/
@WebServlet(name = "LoginServlet", urlPatterns = {"/LoginServlet"})
public class LoginServlet extends HttpServlet {
@EJB(name="login",beanInterface=GestioneLoginLocal.class)
private GestioneLoginLocal login;
/**
* Processes requests for both HTTP <code>GET</code> and <code>POST</code> methods.
* @param request servlet request
* @param response servlet response
* @throws ServletException if a servlet-specific error occurs
* @throws IOException if an I/O error occurs
*/
protected void processRequest(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html;charset=UTF-8");
PrintWriter out = response.getWriter();
try {
// out.println("<html>");
// out.println("<head>");
// out.println("<title>Servlet LoginServlet</title>");
// out.println("</head>");
// out.println("<body>"+st);
// out.println("<h1>Servlet LoginServlet at " + request.getContextPath () + "</h1>");
// out.println("</body>");
// out.println("</html>");
} finally {
out.close();
}
}
// <editor-fold defaultstate="collapsed" desc="HttpServlet methods. Click on the + sign on the left to edit the code.">
/**
* Handles the HTTP <code>GET</code> method.
* @param request servlet request
* @param response servlet response
* @throws ServletException if a servlet-specific error occurs
* @throws IOException if an I/O error occurs
*/
@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
processRequest(request, response);
}
/**
* Handles the HTTP <code>POST</code> method.
* @param request servlet request
* @param response servlet response
* @throws ServletException if a servlet-specific error occurs
* @throws IOException if an I/O error occurs
*/
@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
processRequest(request, response);
String address = "";
String username = request.getParameter("username");
String password = request.getParameter("password");
Object o = login.executeLogin(username, password);
System.out.println("requestttttttttttt");
if (o == null) {
address="index.jsp";
request.getRequestDispatcher("hello.jsp").forward(request, response);
return;
}
HttpSession sessione = request.getSession(true);
sessione.setAttribute("login", o);
if (o instanceof Admin) {
System.out.println("Admin");
sessione.setAttribute("Grado", "Admin");
address="HomeAdmin.jsp";
}
if (o instanceof Cuoco) {
sessione.setAttribute("Grado", "Cuoco");
address="HomeCuoco.jsp";
}
if (o instanceof Cameriere) {
sessione.setAttribute("Grado", "Camerire");
address="HomeCameriere.jsp";
}
if (o instanceof Cliente) {
sessione.setAttribute("Grado", "Cliente");
address="HomeCliente.jsp";
}
getServletContext().getRequestDispatcher("/WEB_INF/hello.jsp").forward(request, response);// questa e la riga dove da l'errore
//request.getRequestDispatcher("hello.html").forward(request, response);
// address="index.jsp";
// dispatcher = getServletContext().getRequestDispatcher("/hello.html");
// dispatcher.forward(request, response);
}
@Override
public String getServletInfo() {
return "Short description";
}// </editor-fold>
}
invece il codice della jsp hello.jspe semplicissimo, e la pagina iniziale quando con netbeans si fa new jsp:
codice:
<%--
Document : hello
Created on : 25-mag-2011, 17.18.27
Author : orphen
--%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JSP Page</title>
</head>
<body>
<h1>Hello World!</h1>
</body>
</html>
quella invece della jso che chiame la servlet e la index.sp, il codice e questo:
codice:
<%--
Document : index
Created on : 10-mag-2011, 17.19.36
Author : orphen
--%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JSP Page</title>
</head>
<body>
<h1>Hello World!</h1>
<% Object u = session.getAttribute("login");
if(u==null){
%>
<FORM METHOD="POST" ACTION="LoginServlet">
Username: <INPUT TYPE="text" NAME="username" SIZE=10>
Password: <INPUT TYPE="password" NAME="password" SIZE=12>
<INPUT TYPE=submit NAME="Submit" VALUE="Ok">
<INPUT TYPE=reset NAME="Cancel" VALUE="Annulla">
</FORM>
<% } else{
out.println("benvenuto "+ session.getAttribute("Grado"));
} %>
AggiungiPersonale
</body>
</html>
non so se serve anche il codice del bean... ma il bean fa tutte le operazione senza nessun errore restituisce corretamente anche l'user.
il percorso di hello.jsp è giusto si trovaall'interno di web-inf, mentre hello.html si trova nella cartella web del progetto quindi con path uguale alla index.