Link to home
Start Free TrialLog in
Avatar of almaha
almahaFlag for Saudi Arabia

asked on

my first servlet

i am really very overwhelmed and i can't find something on the internet to take me step by step. i found something in java.sun.com
http://java.sun.com/developer/onlineTraining/J2EE/Intro2/servlet/servlet.html

but still not easy enough!

1. i am not sure where 2 put the xxx.html file
2. i am not sure where 2 put the xxx.java file
3. i am not sure if its ok 2 use an edito like eclipse 2 create the xxx.java file + the xxx.html file
4. i am not sure how 2 compile the xxx.java file << main issue
5. i got the run.bat running correctly but i don't have the file deployer.jar!

i will paste my code:
1. sallam.html:
<HTML>
  <HEAD>
    <TITLE>
      Sallam
    </TITLE>
  </HEAD>
  <BODY BGCOLOR="WHITE">
    <BLOCKQUOTE>
      <H3>Sallam</H3>
    </BLOCKQUOTE>
  </BODY>
</HTML>

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("<HTML><HEAD><TITLE>");
          out.println("Servlet Example - Sallam");
          out.println("</TITLE></HEAD><BODY>");

          // write sallam
          out.println("<H1>Sallam</H1>");
          
          // close the page
          out.println("</BODY></HTML>");

          // 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
ASKER CERTIFIED SOLUTION
Avatar of bloodredsun
bloodredsun
Flag of Australia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of almaha

ASKER

I am not using TomCat alone. I am using JBoss.
I know i have 2 have basic knowledge about using JBoss first.
I am finding it very difficult to understand how servlets work and how 2 set everything up.
That's what i needed, a good site to start understanding about servlets and JBoss, i guess.....
Eclipse is not making it easier by asking me about all the package, file, class info. I mean all i have is a simple html and a java file. i only want to make a successful HelloWorld servlet working :s
Thanks,
Maha