almaha
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.ServletConfi g;
import javax.servlet.ServletExcep tion;
import javax.servlet.http.HttpSer vlet;
import javax.servlet.http.HttpSer vletReques t;
import javax.servlet.http.HttpSer vletRespon se;
/** 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("sallam Servlet: 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("t ext/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></HEA D><BODY>") ;
// write sallam
out.println("<H1>Sallam</H 1>");
// 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("sallam Servlet: destroy()");
}//destroy
}//Class sallamServlet
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.ServletConfi
import javax.servlet.ServletExcep
import javax.servlet.http.HttpSer
import javax.servlet.http.HttpSer
import javax.servlet.http.HttpSer
/** 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("sallam
}
/**
* 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("t
// obtain the writer to write the response
PrintWriter out = response.getWriter();
// write the page title
out.println("<HTML><HEAD><
out.println("Servlet Example - Sallam");
out.println("</TITLE></HEA
// write sallam
out.println("<H1>Sallam</H
// 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("sallam
}//destroy
}//Class sallamServlet
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
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