the HelloWorld servlet
almaha1980 May 15, 2005 3:59 AMi have been trying to figure out if what i am doing is correct or not.
i run the server from here:
C:\jboss-4.0.1sp1\bin\run.bat
the server is running correctly, no errors. everything is fine. no errors with classpath or anything....
then i open
http://localhost:8080/jmx-console/
working fine also
i go to the command line and i compile the servlet
javac sallamServlet.java
compiled.
now, what do i do to run the servlet?
i went to IE and typed down
http://localhost:8080/jmx-console/FirstServlet.sallamServlet
not working....
this is the path:
C:\jboss-4.0.1sp1\server\default\deploy\FirstServlet
1) .project
<?xml version="1.0" encoding="UTF-8"?>
FirstServlet
2) sallamServlet.java
package deploy.FirstServlet;
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
/** This servlet Says Sallam to the user in a HTML page. */
public class sallamServlet extends HttpServlet {
/**
* This method will be called by the Servlet Container when
* this servlet is being placed into service.
* @param config - the ServletConfig object that
* contains configutation information for this servlet.
*/
public void init(ServletConfig config) {
System.out.println("sallamServlet: init()");
}
/**
* This method handles the HTTP GET requests for this servlet.
* It says Sallam to the user in an HTML page.
* @param request - object that contains the request the
* client has made of the servlet.
* @param response - object that contains the response the servlet
* sends to the client.
* @exception java.io.IOException - if an input or output error is
* detected when the servlet handles the GET request.
* @exception ServletException - if the GET request could not be handled.
*/
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
// write the response to be displayed
// set the response type
response.setContentType("text/html");
// obtain the writer to write the response
PrintWriter out = response.getWriter();
// write the page title
out.println("");
out.println("Servlet Example - Sallam");
out.println("");
// write sallam
out.println("<H1>Sallam</H1>");
// close the page
out.println("");
// close the writer
out.close();
}//doGet
/** This method will be called by the Servlet Container when this servlet
** is being taken out of service.
*/
public void destroy() {
System.out.println("sallamServlet: destroy()");
}//destroy
}//Class sallamServlet
3) sallamServlet.class
was created when i compiled the java file
4) sallam.html >> not sure why i wrote this one :s
Sallam
<H3>Sallam</H3>
-----------------------------------------------------------------------------------
Thanks,
Maha