Run servlet from statelesssessionbean

hi,
   Can anybody help me about ............
How can i run(call) servlet from stateless sessionBean (EJB).
Code to call(run) servlet from stateless sessionbean

Hi
Actually it is not advisable to call an servlet from  a session bean .
   I mean you can not create an object of servlet from session bean .
In otherway it can be possible if your session bean  can call this through an protocol.
  means you can create an URL or URL connection class and call it through http protocol.
i .e we can create URLConnetion ( HttpURLConnection ) object to that servlet  from a session bean.
I hope this will help you some extent to solve your problem.
Thanks
Mrutyunjaya Tripathy

Similar Messages

  • Run servlet from form action tag

    This is my first post to this forum, thanks in advance for any and all help!
    I'm utilizing Tomcat 4.0.1. I've got the following form tag within my JSP:
    <form name="orderForm" method="GET" action="/myAppName/myServletName">
    I've made the context entry for myAppName within ..tomcat/conf/server.xml.
    I've got a properly formatted ..tomcat/webapps/myAppName/web-inf/web.xml
    When submitting the form, Tomcat immediately reports that the resource (myServletName) is unavailable.
    I've download the bookstore sample app from Sun; it is working properly.
    Any idea what I'm missing here?
    The bookstore app calls the servlet from a hyperlink rather that a form action. Do JSP's treat forms differently when calling servlets?
    Thanks again for any assistance.
    Bruce

    Yes, my .class files in in Tomcathome/webapps/appname/web-inf/classes
    If I try and call the servlet from the Address box of the browser, I get the same error listed above.
    Here is the contents of my Tomcathome/webapps/appname/web-inf/web.xml:
    <-- entry begins here
    <?xml version="1.0" encoding="ISO-8859-1"?>
    <!DOCTYPE web-app
    PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.2//EN"
    "http://java.sun.com/j2ee/dtds/web-app_2_2.dtd">
    <web-app>
         <servlet>
              <servlet-name>myServletName</servlet-name>
              <servlet-class>myServletName</servlet-class>
         </servlet>
         <servlet-mapping>
              <servlet-name>myServletName</servlet-name>
              <url-pattern>/myServletName</url-pattern>
         </servlet-mapping>
    </web-app>
    < -- entry ends here
    Here is the entry I've made in Tomcathome/conf/server.xml:
    <--entry begins here
    <Context path="/appName" docBase="appName" debug="0" reloadable="true" />
    <--entry ends here
    The only Tomcat related entry in my classpath is:
    d:\jakarta-tomcat-4.0.1\common\lib\servlet.jar;
    Again, thanks for all your assistance...this is driving me nuts (granted, it wasn't a long trip!)
    Bruce

  • How to run servlet from JSP page

    A simple JSP page,where I will put a button.And on clicking..it will invoke the servlet and the servlet will send the result to the jsp page...
    Please give the instructions with examples...
    Thanks in advance...

    hi,
    Create a jsp inside webapps/root
    <a href="./howtocode" > click to call servlet </a>and follow the steps
    http://forum.java.sun.com/thread.jspa?threadID=5202830

  • Running servlets from directories external to weblogic installation

              Hi:
              How do I set create webapp whose html and WEB-INF is in a directory other than
              ./config/domainname/applications?
              I tried changing config.xml with no avail. Can some guru please guide me?
              Tnanks
              keith
              

    I stand correct. It actually worked after I moved the entry to be the first
              entry.
              "Keith" <[email protected]> wrote in message
              news:[email protected]...
              > It does not seem to work for WL 6.0 on Solaris like Joe described. This is
              > the entry which I've made in config.xml:
              > <Application
              > Deployed="true"
              > Name="pqr"
              > Path="/home/keith/work"
              > >
              > <WebAppComponent
              > Name="yyy"
              > Targets="keith"
              > URI="testcase"
              > />
              > </Application>
              >
              > Thanks
              > Keith
              >
              > "Srinagesh Susarla" <[email protected]> wrote in message
              > news:[email protected]...
              > > Keith,
              > > please try this and let me know.
              > > edit config.xml !Im using Nt hence the structure!
              > >
              > > <Application Deployed="true" Name="pqr" Path="d:\\work">
              > > <WebAppComponent Name="yyy" Targets="myserver" URI="testcase"/>
              > > </Application>
              > >
              > > either testcase.war.. or the directory itself!
              > > I mean d:\work\testcase\ is the place where my html, jsps and WEB_inf
              > directory are
              > > present...
              > >
              > > hope this helps!
              > > -nagesh
              > >
              > > PS: ur url will now be http://host:port/yyy/whatever.jsp
              > >
              > > Joe wrote:
              > >
              > > > Keith,
              > > >
              > > > I have asked BEA for the same question ...they said to me the names
              > "config" and
              > > > "applications" are HARD-CODED :-(
              > > >
              > > > Due to this dictatorial "answer" I have to create on my SUN solaris
              the
              > following
              > > > structure (same for NT):
              > > >
              > > > /opt/joe/config/mydomain/applications
              > > >
              > > > /opt/joe/config/mydomain/applications/myWebApp
              > > >
              > > > WLS600 home directory is opt/wls600
              > > >
              > > > I must "trepan" wls600 using the following script (stored in
              > /opt/joe/config/mydomain):
              > > >
              > > > #!/bin/sh
              > > >
              > > > WL_HOME=/opt/wls600/wls6.0
              > > >
              > > > JAVA_HOME=/opt/wls600/jdk130/jre
              > > >
              > > > JAVA_OPTIONS="-hotspot -ms64m -mx128m"
              > > >
              > > > MY_HOME=/opt/joe/config/mydomain
              > > >
              > > > START_POINT=/opt/joe
              > > >
              > > > # same as usual
              > > >
              > > > ..
              > > >
              > > > #
              > > > cd $START_POINT
              > > >
              > > > # same as usual
              > > >
              > > > ...
              > > >
              > > > #
              > > > java $JAVA_OPTIONS -classpath $CLASSPATH \
              > > >
              > > > -Dweblogic.Domain=mydomain \
              > > >
              > > > -Dweblogic.Name=myserver \
              > > >
              > > > -Djava.security.policy==$WL_HOME/lib/weblogic.policy \
              > > >
              > > > weblogic.Server
              > > >
              > > > You can either create a symbolic link from the $WL_HOME/config to your
              > "mydomain".
              > > > In this case you need not to trepan WLS with the directory "config".
              > However, the
              > > > name "applications" must be STERNLY kept. Otherwise WLS trepans you,
              > too. It creats
              > > > hiddenly a directory named "applications"; uses it and cries foul with
              a
              > lot of weird
              > > > messages :o(
              > > >
              > > > Joe
              > > >
              > > > "Keith" <[email protected]> wrote:
              > > > >
              > > > >Hi:
              > > > > How do I set create webapp whose html and WEB-INF is in a
              directory
              > other
              > > > >than
              > > > >./config/domainname/applications?
              > > > > I tried changing config.xml with no avail. Can some guru please
              > guide
              > > > >me?
              > > > >
              > > > >Tnanks
              > > > >keith
              > >
              >
              >
              

  • Opening new child window - Running servlet

    Hi
    Currently , I have a javascript code that opens a child window. This child window is a Java Server Page called showdata.jsp that uses some data from the database.
    I have used this function to open my page :
    <script language="JavaScript">
    function open_a_window(){
    childwin = window.open("showdata.jsp","dataname", "height=300,width=100");
    </script>Ideally, a servlet should be executed to do the business logic and extract the data that will be displayed on showdata.jsp. Moreover, the user may perform search in the child window, to filter or find the results returned. My questions are as follows:
    1. How to run servlet from Javascript that does the logic and then the results are displayed in showdata.jsp (as a child window)?
    2. How to go about filtering or finding results in showdata.jsp while it is open ? what is the recommended method? because the results have a check box next to them and when user choses and closes window they are reported back to the main JSP which opened the child JSP.
    Any suggestions, reading materials, code , etc is very appreciated.
    Thanks in advance
    Agapito

    Yes you can....
    and the Best way to do it make a Collection of Data Transaction Object you have defined.
    Just as an Example.
    Say your are displaying results of an Employee which contains properties like EmployeeID,Employee Name,Email Address,Contact Information in a Table try to get the results something like
    ArrayList<EmployeeDTOBean> By considering the above example
    lets take a small example
    public class EmployeeDTOBean implements Serializable{
    private int empid;
    private String empName;
    private String empEmail;
    private String empContactInfo;
    // Getters & setters for all the defined properties.
    }and try to get all these results throught a Data Access Object which provides you few methods to fetch relavant results.
    in the above case.
    public List<UserBean> getEmployeeResult(int baseEmpId){
        List<UserBean> aList = new ArrayList<UserBean>();
        UserBean ub = null;
        try{
          con = DbUtils.getConnection();
          pstmt = con.prepareStatement("select emp_id,emp_name,emp_email,emp_contact from employee where base_emp_id = ?");
          pstmt.setInt(1,baseEmpId);
          rs =  pstmt.executeQuery();
          while(rs.next()){
              ub = new UserBean();
              ub.setEmpid(rs.getInt("emp_id"));
              ub.setEmpName(rs.getString("emp_name"));
              ub.setEmpEmail(rs.getString("emp_email"));
              ub.setEmpContact(rs.getString("emp_contact"));
              aList.add(ub);
       }catch(Exception exp){
            LoggingUtils.logException(exp,"In getEmployeeResult("+baseEmpId+")");
       }finally{
           try{
                if(rs != null)
                  rs.close();
                if(pstmt != null)
                  pstmt.close();
                if(con != null && !con.isClosed())
                  con.close();
           }catch(Exception e){
                    LoggingUtils.logException(exp,"In getEmployeeResult("+baseEmpId+")");
           }finally{
                  con = null;
                  pstmt = null;
                  rs = null; 
       returns aList;
    } NOTE: It would be a Gr8 if you can refer to DAO pattern for a better understading of what trying to explain.Please refer to
    http://java.sun.com/blueprints/corej2eepatterns/Patterns/DataAccessObject.html
    Now after getting this results from a Controller save it in the scope of session and try to operate your logic and present your data this would enable you to pickup results from the session not going back to database again.
    And if you need a better way to present that kind of data in crisp and formatted way.I'd recommend you to go with a specific Tag Library
    Please refer to
    http://displaytag.sourceforge.net/
    and in order to that specfic it is preety simple if you go with the documentation which they provide.
    Hope this might help :)
    REGARDS,
    RaHuL

  • Set Path for running servlets

    Hi,
    Just started learning JSP.
    Am trying to run the helloworld.java
    from command prompt has c:\Tomcat 4.1\webapps\examples/WEB-INF/classes/HelloWorld.java.It says pacakage javax.servlet.http doesnot exist.Why is this?am i doing some thing wrong?
    I tried to run it from Tomcat as well.
    http://localhost:8080/examples/WEB-INF/classes/HelloWorld.java
    It says The requested resource (/examples/servlets/helloworld) is not available.
    Any help appreciated
    Thanx
    Shenoy

    You can not run servlets from the command line. You need to run them from the browser. The url should look like:
    http://localhost:8080/examples/servlet/HelloWorld.java
    Look at the tomcat examples at
    http://localhost:8080/index.jsp

  • Creating new JSF2 pages from a running Servlet (3.0) or JSF2 page?

    I'm new to JEE6 web apps with JSF 2.x frontends (GlassFish 3), and I still wasn't able to find a solution for this dynamic JSF 2.x problem:
    *From inside a running JSF 2.x web app (Servlet 3.0), which possibilities (if any) do I have to dynamically add generated JSF pages (whole new .xhtml files) to specific folders of the (exploded) document root, so that these pages can be dispatched to the client like any traditional, statically-deployed one?*
    Background: An app for "promoting" authors/editors (content providers) which has these few main requirements:
    <ol>
    <li>New providers will register under <tt>www.acme.com/app/register.xhtml</tt>.</li>
    <li>The system will grant each provider "sub-domain" associated with web space under
    <tt>www.acme.com/app/<b>providerX</b></tt> where providerX is an arbitrary sub-domain name chosen by the provider during the registration.</li>
    <li>Each provider will initially have some pre-defined pages in their document context root, e.g.
    <tt>www.acme.com/app/providerX/index.xhtml</tt>, <tt>about-me.xhtml</tt>, <tt>contact.xhtml</tt>, etc.</li>
    <li>Each provider will have an administration console for managing 2 tasks:
    <ul>
    <li type="a"><tt>www.acme.com/app/providerX/admin/page-manager.xhtml</tt> </li>
    <li type="a"><tt>www.acme.com/app/providerX/admin/customer-manager.xhtml</tt></li>
    </ul>
    to specify new pages with offers, publish these pages in their document context root, e.g. <tt>www.acme.com/app/<b>providerX</b>/<b>my-services</b>.xhtml</tt> (customized page name), and
    to manage their readers/customers, respectively.
    </li>
    <li>Thus, each providerX will also have a pre-deployed customer registration page running, which creates standard customer accounts. E.g.:
    <ul>
    <li type="disc"><tt>www.acme.com/app/providerX/customers/registration.xhtml</tt></li>
    <li type="disc"><tt>www.acme.com/app/providerX/customers/login.xhtml</tt></li>
    <li type="disc"><tt>www.acme.com/app/providerX/customers/customer-account-dashboard.xhtml</tt></li>
    </ul>
    </li></ol>
    Please note: I know that for such kind of systems a CMS would be more suitable, but is such a system -- here aiming at only basic functionality -- also realizable in pure JEE 6 technologies, i.e. w/o CMS???
    <b>The unclear main aspect is stated in my initial question above. Basically, I hope to get these clarifications:</b>
    <ol>
    <li><b>Which app architecture designs can I use to deploy new generated JSF pages or servlets from within a running JSF page or servlet???</b></li>
    <li><b>Supposing that all relevant page description data provided by a provider is stored in a db:
    Where can I "cache" the new .xhtml pages generated from these data on-the-fly when (a) an exploded WAR, and (b) a packaged WAR is running???</b>
    The pages shall be "hooked" to the scope (doc root) of the respective provider and dispatches by the <tt>FacesServlet</tt> as such.</li>
    </ol>
    Due to the crucial importance in a current project, I'd really appreciate any constructive help very much.
    Natalia.

    Natalia F. wrote:
    Determining you as one of the experts in this forum, please, could I ask you how you'd solve this kind of web apps in JSF2 (one of the requirements stated at the beginning of this thread):I'm certainly an expert at having an opinion about everything.
    >
    Having a "page-manager.xhtml" JSF2 UI at "/page-manager" context that lets registered member X define a website (=a set of .jsf/.xhtml pages) in a new context "/websiteX" (where "websiteX" is freely chosen and associated with dedicated webspace to store the pages in the filesystem):
    How to store these dynamically created website pages from within the PageManagerServlet?
    <ol><li type="a">Could I create a new exploded WAR structure in the filesystem (or elsewhere) when a new context is defined, and then store new .jsf/.xhtml files therein when a new page is defined, all this with usual file operations? -- Would this be enough, or...</li>
    <li type="a">...after storing a new page, would I need to explicitly tell the container to deploy the page (or re-deploy the WAR(?)) so that I can instantly test/run the page when it is new/modified, or will it be compiled automatically when pointing a browser to it???
    I guess both is possible, but for performance reasons, a pre-compile would be better. How can I achieve this?</li>
    </ol>
    Thank you a million for your help, Natalia.I only see mention of xhtml files - that is the easy part. But XHTML files don't actually do anything at all. What about classes like JSF managed beans? jar libraries? database connections and ORM/JPA support which also adds the complexity of having to deal with all the configuration descriptor files? Even if you can automatically deploy all that, replacing existing classes and reloading them is a whole different matter.
    My "expert" opinion: this cannot be done with JSF. In fact the only Java web framework which I can think of that has any chance of making something like this possible is Play framework. I'd really take the road that EJP took: make the content dynamic, not the webapp.

  • How to call Servlet from jsp page and how to run this app using tomcat..?

    Hi ,
    I wanted to call servlet from jsp action i.e. on submit button of JSP call LoginServlet.Java file.
    Please tell me how to do this into jsp page..?
    Also i wanted to execute this application using tomcat.
    Please tell me how to do this...? what setting are required for this...? what will be url ..??
    Thanks.

    well....my problem is as follows:
    whenever i type...... http://localhost:8080/appName/
    i am getting 404 error.....it is not calling to login.jsp (default jsp)
    but when i type......http://localhost:8080/appName/login.do........it executes servlet properly.
    Basically this 'login.do' is form action (form action='/login.do').....and i wanted to execute this from login jsp only.(from submit button)
    In short can anyone please tell me how to diaplay jsp page using tomcat 5.5
    plz help me.

  • How can i call a servlet from a servlet ?

    Hello,
    Can i call a Servlet from within a Servlet ?
    and is it "right thing" to Do ?
    Thanks

    JMO, but I wouldn't do it like this.
    Don't have a remote object like a servlet doing database queries for your app. That will mean TWO network hops for every query if the database resides on another machine. The network is the biggest bottleneck you've got.
    Write a JavaBean that does the database stuff for you and just have the first servlet instantiate it when it needs it. A Bean has a better chance of being reused, too. Write a TableGateway or DAO for your object.
    Or write an EJB to do it.
    The only time I've done a servlet-to-servlet connection like that was for one servlet running in a DMZ that would authenticate a user and then forward the request to another servlet running inside the second firewall.
    I wouldn't encapsulate database query logic in a servlet like that. JMO - MOD

  • Problem while calling servlet from java bean

    I am trying to call a servlet from java bean in cep.
    My java bean:
    package com.bea.wlevs.example.algotrading;
    import com.bea.wlevs.ede.api.StreamSink;
    import com.bea.wlevs.example.algotrading.event.MarketEvent;
    import javax.xml.bind.JAXBContext;
    import javax.xml.bind.Unmarshaller;
    import java.io.BufferedReader;
    import java.io.BufferedWriter;
    import java.io.IOException;
    import java.io.InputStreamReader;
    import java.io.OutputStreamWriter;
    import java.io.StringReader;
    import java.net.MalformedURLException;
    import java.net.URL;
    import java.net.URLConnection;
    public class MarketEventBean implements StreamSink {
         String s=null;
         public void onInsertEvent(Object event) {
              if (event instanceof MarketEvent) {
                   MarketEvent marketEvent = (MarketEvent) event;
                   try {
                        JAXBContext cxt = JAXBContext.newInstance(MarketEvent.class);
                        Unmarshaller unmarsh = cxt.createUnmarshaller();
                        StringReader strReader = new StringReader(marketEvent.getString_1());
                        MarketEvent obj = (MarketEvent) unmarsh.unmarshal(strReader);
                        s=obj.getSymbol();
                        System.out.println("data: " + s);
                   } catch(Exception e) {
                        e.printStackTrace();
                   try {
                        System.out.println("test1");
         URL url = new URL("http://172.18.21.94:7001/AppServletrecv-Model-context-root/ReceiveServlet");
         URLConnection conn = url.openConnection();
              System.out.println("test2");
         conn.setDoOutput(true);
              System.out.println("test3");
         BufferedWriter out =
         new BufferedWriter( new OutputStreamWriter( conn.getOutputStream() ) );
         out.write("symbol="+s);
              System.out.println("test4");
         out.flush();
         System.out.println("test5");
         out.close();
         System.out.println("test6");
         BufferedReader in =
         new BufferedReader( new InputStreamReader( conn.getInputStream() ) );
              System.out.println("test7");
         String response;
         while ( (response = in.readLine()) != null ) {
         System.out.println( response );
         in.close();
         catch ( MalformedURLException ex ) {
         // a real program would need to handle this exception
         catch ( IOException ex ) {
         // a real program would need to handle this exception
    My servlet code:
    package model;
    import javax.servlet.http.HttpServlet;
    import java.io.IOException;
    import java.io.PrintWriter;
    import javax.servlet.http.HttpServlet;
    import javax.servlet.http.HttpServletRequest;
    import javax.servlet.http.HttpServletResponse;
    public class ReceiveServlet extends HttpServlet {
    private final static String _SYMBOL = "symbol";
    public void doPost(HttpServletRequest request, HttpServletResponse response) {
    * Get the value of form parameter
    // private final static String USERNAME = "username";
    String symbol = request.getParameter( _SYMBOL );
    * Set the content type(MIME Type) of the response.
    response.setContentType("text/html");
    * Write the HTML to the response
    try {
    PrintWriter out = response.getWriter();
    out.println("<html>");
    out.println("<head>");
    out.println("<title> A very simple servlet example</title>");
    out.println("</head>");
    out.println("<body>");
    out.println("<h1>Hello " + symbol +"</h1>");
    out.println("</body>");
    out.println("</html>");
    out.close();
    } catch (IOException e) {
    Web.xml:
    <?xml version = '1.0' encoding = 'windows-1252'?>
    <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
    version="2.5" xmlns="http://java.sun.com/xml/ns/javaee">
    <servlet>
    <servlet-name>ReceiveServlet</servlet-name>
    <servlet-class>model.ReceiveServlet</servlet-class>
    </servlet>
    <servlet-mapping>
    <servlet-name>ReceiveServlet</servlet-name>
    <url-pattern>/ReceiveServlet</url-pattern>
    </servlet-mapping>
    </web-app>
    My servlet is running in weblogic server.
    But when I am running this program in weblogic server side there is no log.
    Edited by: 856272 on Jun 23, 2011 6:43 AM

    I would run both sides in a debugger and see what code is getting invoked

  • How to run servlet in java webserver2.0

    how to configure java webserver2.0 and how to run servlet in that

    Hi Friend,
    Try changing the servlet code to this and just tell wat happens after this.
    and wat can you see on your Browser Screen.
    import java.io.*;
    import javax.servlet.*;
    import javax.servlet.http.*;
    import java.sql.*;
    public class login extends HttpServlet {
    public void doGet(HttpServletRequest req,HttpServletResponse res) throws ServletException,IOException
    if (req.getParameter("t1") == null || req.getParameter("t2") == null)
    out.println("Enter User Name And Password");
    String uid=req.getParameter("t1");
    String pwd=req.getParameter("t2");
    res.setContentType("text/html");
    PrintWriter out=res.getWriter();
    out.println("<html>"); out.println("<head>");
    out.println("<title>Login</title>"); out.println("</head>");
    out.println("<body>");
    try { Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
    catch(ClassNotFoundException e)
    out.println("<h3>"+e+"</h3>");
    try{
    Connection con=DriverManager.getConnection("jdbc:odbc:ms","scott","tiger");
    PreparedStatement psm=con.prepareStatement("select * from reg where uid1=? and pwd=?");
    psm.setString(1,uid);
    psm.setString(1,pwd);
    ResultSet rs=psm.executeQuery();
    if(rs.next())
    { out.println("<html><head><title>WELCOME</title></head>");
    out.println("<body><b><i>Hello user "+uid+"</b></i>");
    out.println("</body></html>"); }
    else
    res.sendRedirect("http://localhost:8080/login.html");
    } catch(SQLException e)
    { e.printStackTrace();}
    rs.close();
    con.close();
    out.close();
    After this try creating a odbc for oracle database at control panel with the name ms.
    Please inform me wat happens after this and friend do give some information about wat kind of web-server are you using.Because calling of your servlets differs the way your configure your web-server and the default configurations differ from web-server to web-server.
    Regards,
    RAHUL

  • How to compile and run servlets in Eclipse?

    Does somebody known how can I compile and run servlets in Eclipse IDE? I've added and configured Tomcat's plugin. I've created a project with my example servlets source, and I don't know what farther. How do I have compile it without main method? I must add web.xml file from Tomcat's directory into projects in Eclipse and modify it?
    THX Chudzik

    Try googling for "eclipse servlet", surely someone has written instructions.

  • Problem in invoking a servlet from another PC

    hi
    i am trying to invoke a servlet running on apache tomcat 5.0.28 from another PC, my j2me wireless toolkit is on one PC and it runs a MIDlet that invokes a servlet on another PC, but am getting an exception connectionNotFound....
    both the computers are on LAN, what do i do?
    Need guidance

    No, i think tomcat server is enough.. have u checked your servlet from browser?
    I got the same error in black berry application and at that time i found that its due to servlet config in web.xml
    Have u configured your servlet in web.xml?
    One suggestion.. change your URL to www.google.com and then run your MIDlet.. it confermed that your midlet is OK
    Http request is fine to send data from your WTK.
    About apache http "NO IDEA"
    Thks

  • Problems running servlet due to missing classes?

    Hi everyone,
    I am doing a project which requires me to convert a java coding into a servlet. This java coding I am working on is some kind of location based service which tracks people (receiving an argument of a string as IP). It imports an external SDK called Ekahau SDK (some off the shelve product). Now I wish to convert it into a servlet so that the function that the java coding performs can be run from a webpage i created.
    I have previously posted a thread on this forum called "Converting java coding into servlets?" when I had trouble compiling the servlet. Now that I could compile the servlet already, I still have problems running the servlet from my browser.
    The webserver I am using is Apache Tomcat. Previously I was trying Apache HTTP server but since now I need to use servlet, I have shifted to Tomcat instead. I have been getting these "java.lang.NoClassDefFoundError:" when running the servlet from the browser. From the previous thread, I got suggestions from the replies saying that I need to put the jar files I need into my "C:\Tomcat\webapps\try\WEB-INF\lib" directory. I have been looking for the missing jar files from the internet and putting them into my "C:\Tomcat\webapps\try\WEB-INF\lib", but each time after adding a new jar file, I get another new "java.lang.NoClassDefFoundError:". Are the missing jar files really the problems? Cause it seems a bit weird to me that I need some many jar files which I dont even know why I need them for.
    The HTTP status 500 error look like this:
    description
    The server encountered an internal error () that prevented it from fulfilling this request.
    exception
    javax.servlet.ServletException: Servlet execution threw an exception
    root cause
    java.lang.NoClassDefFoundError: org/apache/excalibur/configuration/CascadingConfiguration
    com.ekahau.G.N.A(Unknown Source)
    com.ekahau.G.N.<init>(Unknown Source)
    com.ekahau.sdk.imp.yax.D.<init>(Unknown Source)
    com.ekahau.sdk.imp.yax.E.connect(Unknown Source)
    com.ekahau.sdk.PositioningEngine.connect(Unknown Source)
    coreservlets.testing.find(testing.java:75)
    coreservlets.testing.doGet(testing.java:36)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:690)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
    Here are the series of jar files I have been looking from the internet to add them into my "C:\Tomcat\webapps\try\WEB-INF\lib" directory:
    1) org/apache/commons/collections/Closure
    2) org/apache/log4j/Logger
    3) org/apache/commons/lang/Validate
    4) org/apache/excalibur/configuration/CascadingConfiguration
    Please help~~ Thanks a lot.
    My servlet coding is like this:
    package coreservlets;
    import java.io.*;
    import java.util.*;
    import java.io.IOException;
    import java.io.PrintWriter;
    import javax.servlet.ServletException;
    import javax.servlet.http.HttpServlet;
    import javax.servlet.http.HttpServletRequest;
    import javax.servlet.http.HttpServletResponse;
    import com.ekahau.sdk.*;
    public class testing extends HttpServlet
         String ipAddress;
         int result;
           public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
                  ipAddress = request.getParameter("deviceIP");
              try
                   result = find();     
              catch (IOException e)
                   System.out.println("Error..." + e.toString());
              catch (EngineException e)
                   System.out.println("Error..." + e.toString());
              response.setContentType("text/html");
                  PrintWriter write = response.getWriter();
              write.println("<HTML>\n" +
    "<HEAD><TITLE>Tryget</TITLE></HEAD>\n" +
    "<BODY BGCOLOR=\"#FDF5E6\">\n" +
    result +
    "</BODY></HTML>");
           public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
                  doGet(request, response);
         public int find() throws EngineException, IOException
              PositioningEngine.connect();
                  // Find the given device:
                  Device[] devices = PositioningEngine.findDevice("NETWORK.IP-ADDRESS", ipAddress);
                  if (devices.length == 0)
                         System.err.println("Device with IP address " + ipAddress + " not found.");
                   PositioningEngine.disconnect();
                   return 0;
              else
                         TrackedDevice device = new TrackedDevice(devices[0]);
                         // Create a simple handler for locations for one-time usage:
                         LocationEstimateListener estimateListener = new LocationEstimateListener()
                           public void handleLocationEstimate(LocationEstimate locationEstimate, TrackedDevice device)
                                  // Change getLatestLocation to getAccurateLocation if you want
                                  // a bit more accurate but a few seconds delayed location.
                                  Location loc = locationEstimate.getLatestLocation();
                             final double coX = loc.getX();
                             final double coY = loc.getY();
                             try{
                             FileWriter file = new FileWriter ("C:\\Documents and Settings\\xamule\\Desktop\\Testing\\output\\output.txt");
                             String x = Double.toString(coX);
                             String y = Double.toString(coY);
                             String coor = x + "\t" + y;
                             file.write(coor);
                             file.close();
                             catch (IOException e){
                             System.out.println("Error..." + e.toString());
                   StatusListener statusListener = new StatusListener()
                           public void handleStatus(Status status, TrackedDevice device)
                                  System.err.println(new Date()+"\tStatus for device: " + status);
                         // Add listeners and start tracking
                         device.addLocationEstimateListener(estimateListener);
                         device.addStatusListener(statusListener);
                         device.setTrackingParameter("EPE.LOCATION_UPDATE_INTERVAL","6000");
                         device.setTracking(true);
                         // Wait until user inputs something. When he/she does, stop tracking and quit application
                         //BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
                         //in.readLine();
                         // Stop tracking and disconnect from the positioning engine:
                         device.setTracking(false);
                         PositioningEngine.disconnect();
                   return 1;
    }

    Well, it's kind of logical that as you put more jar files (classes) in Tomcat, it changes the error to ask for the classes (inside a jar) it cannot find.
    There was a good class->jar finder on the internet some years ago, but i don't remember the address. Try looking for that and search all the missing classes (NotDefined) and their correspondig jar files.
    Good Luck!

  • How to run Servlet on Tomcat 4.0.1?

    OK. I've made a simple servlet and using Tomcat 4.0.1 on Windows ME. Tomcat's root directory is C:\jakarta-tomcat-4.0.1\webapps\ROOT. I copied folder with my servlet (java's class) in tomcat's root folder. When I try to run the dialog 'File Download' is showen. Why?
    Thanks.

    I have Tomcat 4.0. I am trying to run servlet but I could not manage it. I have put my class file in webapp/root/web-inif/classes/ I can not run my servlet... how can I manage this... what should I do more?
    the errors are :
    type Exception report
    message Internal Server Error
    description The server encountered an internal error (Internal Server Error) that prevented it from fulfilling this request.
    exception
    javax.servlet.ServletException: Cannot allocate servlet instance for path /servlet/Servlet1
         at org.apache.catalina.servlets.InvokerServlet.serveRequest(InvokerServlet.java:419)
         at org.apache.catalina.servlets.InvokerServlet.doGet(InvokerServlet.java:180)
         at javax.servlet.http.HttpServlet.service(HttpServlet.java:740)
         at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
         at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:247)
         at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:193)
         at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:243)
         at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:566)
         at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:472)
         at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:943)
         at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:190)
         at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:566)
         at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:472)
         at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:943)
         at org.apache.catalina.core.StandardContext.invoke(StandardContext.java:2347)
         at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:180)
         at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:566)
         at org.apache.catalina.valves.ErrorDispatcherValve.invoke(ErrorDispatcherValve.java:170)
         at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:564)
         at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:170)
         at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:564)
         at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:468)
         at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:564)
         at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:472)
         at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:943)
         at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:174)
         at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:566)
         at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:472)
         at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:943)
         at org.apache.catalina.connector.http.HttpProcessor.process(HttpProcessor.java:1027)
         at org.apache.catalina.connector.http.HttpProcessor.run(HttpProcessor.java:1125)
         at java.lang.Thread.run(Thread.java:484)
    root cause
    java.lang.NoClassDefFoundError: Servlet1 (wrong name: servlet/Servlet1)
         at java.lang.ClassLoader.defineClass0(Native Method)
         at java.lang.ClassLoader.defineClass(ClassLoader.java:486)
         at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:111)
         at org.apache.catalina.loader.WebappClassLoader.findClassInternal(WebappClassLoader.java:1643)
         at org.apache.catalina.loader.WebappClassLoader.findClass(WebappClassLoader.java:937)
         at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1372)
         at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1254)
         at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:867)
         at org.apache.catalina.core.StandardWrapper.allocate(StandardWrapper.java:655)
         at org.apache.catalina.servlets.InvokerServlet.serveRequest(InvokerServlet.java:400)
         at org.apache.catalina.servlets.InvokerServlet.doGet(InvokerServlet.java:180)
         at javax.servlet.http.HttpServlet.service(HttpServlet.java:740)
         at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
         at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:247)
         at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:193)
         at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:243)
         at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:566)
         at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:472)
         at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:943)
         at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:190)
         at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:566)
         at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:472)
         at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:943)
         at org.apache.catalina.core.StandardContext.invoke(StandardContext.java:2347)
         at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:180)
         at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:566)
         at org.apache.catalina.valves.ErrorDispatcherValve.invoke(ErrorDispatcherValve.java:170)
         at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:564)
         at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:170)
         at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:564)
         at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:468)
         at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:564)
         at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:472)
         at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:943)
         at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:174)
         at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:566)
         at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:472)
         at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:943)
         at org.apache.catalina.connector.http.HttpProcessor.process(HttpProcessor.java:1027)
         at org.apache.catalina.connector.http.HttpProcessor.run(HttpProcessor.java:1125)
         at java.lang.Thread.run(Thread.java:484)

Maybe you are looking for