la Servlet ne reponds pas
Bonjour a tous,
debutant en J2EE.
voila, je viens de faire un petit code de servlet qui permet d'envoyer une reponse en me disant que "The JDBC URL has been set as a context attribute".
Apres avoir lance la servlet le browser me repond "The request ressource(/ctx/servlet/SetttingCntx) is not available.
voici mon code complet:
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
| import javax.servlet.*;
import java.io.*;
public class SetttingCntx extends GenericServlet
{
ServletContext ctx;
public void init (ServletConfig cfig)
{
/*Obtain the ServletContext object */
ctx=cfig.getServletContext();
}
public void service(ServletRequest request, ServletResponse response) throws ServletException, IOException
{
/* set the context attribute*/
ctx.setAttribute("URL","jdbc:odbc:EmployeesDB");
/*obtain the PrintWriter object*/
PrintWriter pw=response.getWriter();
/* Send response to indicate that the URL attribute as been set*/
response.setContentType("text/html");
pw.println("<B>The JDBC URL has been set as a context attribute</B>");
}
} |
Ou se trouve le probleme?
J'ai bien fait le deploiement.
La servlet ne reponds pas
En fait c'est normal que la servlet ne reponde pas car il manque un fichier java qui permet de faire la requete donc sans la requete pas de reponse.
voici la fichier de requete:
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
| import javax.servlet.*;
import java.io.*;
public class RetrievingCntx extends GenericServlet
{
ServletContext ctx;
String url;
public void init(ServletConfig cfig)
{
/* obtain the ServletContext object*/
ctx=cfig.getServletContext();
}
public void Service(ServletRequest request, ServletResponse response) throws ServletException, IOException
{
/*Retrieve the URL attribute*/
url=(String)ctx.getAttribute("URL");
/*Obtain a PrintWriter object*/
PrintWriter pw=response.getWriter();
/*Send response to display the value of the URL attribute*/
response.setContentType("text/html");
pw.println("<B>The URL value is </B>: "+ url + "<BR>");
}
} |
Mais la un autre probleme arrive, c'est que ce fichier ne se compile pas.
erreur a la compilation:
Citation:
RetrievingCntx is not abstract and does not override abstract method service(javax.servlet.ServletRequest, javax.servlet.ServletResponse) in javax.servlet.GenericServlet
public class RetrievingCntx extends GenericServlet
1 error
Pourquoi cette erreur ou est le probleme ?