JBoss-IDE 1.2.2 Tutorial 4:
The complete code of 'ComputeServlet' is as follows:
Package tutorial.Web;
Import java.io.ioException;
Import java.io.printwriter;
Import javax.naming.context;
Import javax.naming.initialcontext;
Import javax.rmi.portableremoteObject;
Import javax.servlet.servletException;
Import javax.servlet.http.httpservlet;
Import javax.servlet.http.httpservletRequest;
Import javax.servlet.http.httpservletResponse;
Import tutorial.Interfaces.fibo;
Import tutorial.interfaces.fiboHome;
/ **
* @Author John Doe
*
* @ Web.Servlet Name = "ComputeServlet"
* Display-name = "computation servlet"
* Description = "Servlet That Compute Fibonacci Suite"
*
* @ Web.Servlet-maping url-pattern = "/ compute"
*
* @ Web.env-entry name = "title"
* Type = "java.lang.string"
* Value = "Fibonacci Computation"
* Description = "Example of Env Entry"
*
* @ Web.ejb-ref name = "EJB / FIBO"
* Type = "session"
* Home = "tutorial.interfaces.fibohome"
* Remote = "Tutorial.Interfaces.fibo"
* Description = "Reference to the fibo ejb"
*
* @ jboss.ejb-ref-jndi ref-name = "EJB / FIBO"
* JNDI-NAME = "EJB / TUTORALIAL / FIBO"
* /
Public class computeServlet Extends httpservlet {
PRIVATE FIBOHOME HOME;
PRIVATE STRING VALUE;
Public computeServlet () {
Super ();
}
Public void init () throws servletexception {
Try {
Context context = new initialContext ();
Value = (string) Context.lookup ("java: / comp / env / title);
Object ref = context.lookup ("java: / comp / ENV / EJB / FIBO");
HOME = (FiboHome) PortableremoteObject.narrow (ref, fibohome.class);} catch (exception e) {
Throw New ServleTexception ("Lookup of Java: / Comp / Env / Failed");
}
}
Protected Void Dopost (httpservletRequest Request, HttpservletResponse Response)
Throws servletexception, ioException {
Response.setContentType (Text / HTML ");
PrintWriter out = response.getwriter ();
Out.println ("
Out.println (Value);
Out.println (" Title> HEAD>");
Out.println ("
Out.println ("
Out.println (Value);
OUT.PRINTLN (" h1>");
Try {
Fibo bean = home.create ();
INT LIMIT = 0;
String value = Request.getParameter ("limit");
IF (value! = null) {
Try {
Limit = integer.parseint (value);
}
Catch (Exception E) {
}
}
Double [] result = bean.compute (limited);
Bean.remove ();
Out.println ("
");
Out.print ("THE");
Out.print (Limit);
Out.print ("First Fibonacci Numbers);
For (int i = 0; i Out.println (" Out.println (i); OUT.PRINTLN (":"); Out.println (Result [i]); } Out.println (" p>"); } catch (exception e) { Out.println (E.GetMessage ()); E.PrintStackTrace (OUT); } finally { Out.println (" Body> HTML>"); Out.close (); } } } Generate servlet related files: To generate a web configuration document, we must first set some xdoclet settings. It is like EJB, let us define the settings of Web automatically generated. Right-click on the selected 'Properties' -> 'XDoclet Configurations', pick the 'add' right on the left window, fill in the 'Web' and press 'OK', so adding an XDoclet 'web' generating setting .
");