Java servlets and Tomcat  server

Hi friends
i am using Sun One forte Community edition . i am trying to make a hello world servlet .
there are 2 Files one is Index.html , HelloWorld.java (Servlet)
I call this servlet from the index.html file.
evertime i call it it gives me and error of Apache tomcat file not found .The tomcat server is inbuilt with the Sun One studio.
the directory structure is
-----HOME
-------WEB_FOLDER
----------Index.html
----------WEB-INF
-------------CLASSES
-----------------myServlet (package)
---------------------HelloWorld.java
-------------LIB
The problem is I am not getting how to write the path of servlet in index.html to call the helloWorld servlet.

Make this entry in your server.xml file located in tomcat_dir\conf.
<Context path="/abc"
     docBase="webapps/abc"
     crossContext="true"
     debug="0"
     reloadable="true"
     trusted="false">
</Context>
Suppose i want to develop my servlets in another folder Let it be "XYZ".Then your package statement must be, 'package xyz;'. Place all your servlets in webapps/abc/WEB_INF/classes/xyz dir.
Place all your Jsp(s) and Htmls in webapps/abc/pqrs dir.
Now they all come under one context 'abc'.
Sudha

Similar Messages

  • Serving Java Servlets and JSP

    I have a small hosting company and was wondering what is required to be installed on a Win2k Server to host Java Servlets and JSP pages for a client of mine?

    Ah, so you just want to add a servlet engine to IIS5?
    Tomcat can be used as a plugin for IIS. Check out the Tomcat FAQs - somewhere in there you should find one relating to using Tomcat as an IIS plugin. They're far more comprehensive than I could ever hope to be on the matter!

  • Questions about Java Servlets and JSP

    Hi,
    I'm a confident Java Programmer (and really enjoy using this language) but am very new to Java servlets and Java Server Pages.
    I have previously worked with Perl on my web projects (simple 'league' style voting pages). I read in my 'Core Java' book that I should no longer use perl or even cgi.
    I need to know more about Java servlets and Java Server Pages so I can make the switch to a 'real' programming language.
    I have a few questions:
    How should I start to learn JS and JSP?
    How applicable will the java knowlegdge I have already be?
    Are JSP common on the world wide web?
    What tools do I need to start? (I currently develop in JBuilder and have Java 1.4.1 Standard Edition)
    Is it likey my web host (and others) will support JSP?
    Thank-you very much for helping a novice get started,
    Regards,
    Paul

    Hi, Steve ...has to be frustrating! But do not despair.
    Let's suppose the servlet it's named MyServlet on package org.servlets
    WEB-INF should look:
    WEB-INF
    classes
    org
    servlets
    MyServlet.class
    web.xml
    web.xml file should have this two declarations:
    <web-app>
      <servlet>
        <servlet-name>MyServlet</servlet-name>
        <servlet-class>org.servlets.MyServlet</servlet-class>
      </servlet>
      <!-- other servlets -->
      <servlet-mapping>
        <servlet-name>MyServlet</servlet-name>
        <url-pattern>/MyServlet</url-pattern>
      </servlet-mapping>
      <!-- other servlets mappings -->
    </web-app>Now, once the container starts (Tomcat?), you should be able to see that servlet in:
    http://localhost:8080/[my-context/]MyServletAnd what my-context is? The web application context. This string should be empty if your're deploying to the root context, otherwise should the context name. In Tomcat, deploying to root context defaults to using webapps/ROOT.
    Sorry for my English, but I felt the need to answer your request. I hope it helps despite my writing.

  • Problem with Java Studio Creator and Tomcat Server

    Hi Gays ,
    I have problem:
    here is the error from tomcat 5
    com.sun.rave.web.ui.appbase.ApplicationException: org.apache.jasper.JasperException: java.lang.RuntimeException: java.sql.SQLException: statement handle not executed: getMetaData
    com.sun.rave.web.ui.appbase.faces.ViewHandlerImpl.destroy(ViewHandlerImpl.java: 601)
    com.sun.rave.web.ui.appbase.faces.ViewHandlerImpl.renderView(ViewHandlerImpl.ja va:316)
    com.sun.faces.lifecycle.RenderResponsePhase.execute(RenderResponsePhase.java:87 )
    com.sun.faces.lifecycle.LifecycleImpl.phase(LifecycleImpl.java:221)
    com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:117)
    javax.faces.webapp.FacesServlet.service(FacesServlet.java:198)
    com.sun.rave.web.ui.util.UploadFilter.doFilter(UploadFilter.java:194)
    if i develop application on my pc ( java studio creator with sun apps bundlled) is working perfectly,
    but i migrated application to Tomcat Server ( Database the same - Oracle 10 g)
    i can't show value ( as text) from datasoruce ( is in SessionBean1)
    (Category-.>Subcat->Items->details( url from items table[items.jsp])
    this is a working url "/faces/testpage.jsp?auk_id=31 "
    ( working with sun apps server , but not on Tomcat 5)
    below prerender method in details.java and fragment of details.jsp
    public void prerender() {
    try {
    String idauk = (getExternalContext().getRequestParameterMap().get("auk_id").toString());
    System.out.println("wartosc auk_id " + idauk);
    if (idauk != null) {
    getSessionBean1().getDetailsRowSet().setObject(1,idauk);
    getSessionBean1().getDetailsDataProvider().refresh();
    details.jsp
    xml version="1.0" encoding="UTF-8"?>
    <jsp:root version="1.2" xmlns:f="http://java.sun.com/jsf/core" xmlns:h="http://java.sun.com/jsf/html" xmlns:jsp="http://java.sun.com/JSP/Page" xmlns:ui="http://www.sun.com/web/ui">
    <jsp:directive.page contentType="text/html;charset=UTF-8" pageEncoding="UTF-8"/>
    <f:view>
    <ui:page binding="#{testpage.page1}" id="page1">
    <ui:html binding="#{testpage.html1}" id="html1">
    <ui:head binding="#{testpage.head1}" id="head1">
    <ui:link binding="#{testpage.link1}" id="link1" url="/resources/stylesheet.css"/>
    </ui:head>
    <ui:body binding="#{testpage.body1}" id="body1" style="-rave-layout: grid">
    <ui:form binding="#{testpage.form1}" id="form1">
    <ui:staticText binding="#{testpage.staticText1}" id="staticText1" style="position: absolute; left: 120px; top: 96px" text="#{SessionBean1.testDataProvider.value['Name']}"/>
    </ui:form>
    </ui:body>
    </ui:html>
    </ui:page>
    </f:view>
    </jsp:root>
    Help People ! Any Ideas I'm stuck, why is working with Sun Servet but not with Tomcat and only just thing ?
    Thanks in advance for helping me to resolve the night problem :)

    Hi I found solution, i puted on the page a table -component (with brand new automaticly created dataprovider) , then i set properties visible= false for table, and now I can bind statictext with database field and deploy on tomcat server .
    But i think it is not a elegant solution in page source i habe noused-code.
    Have Any another Ideas. HELP PEOPLE !!!!
    Mariuszek: I use Creator.because right now I can see result of my job and i can qickly change ideas ,
    I tried with JDeveleper but i did'nt find this functionality (wich version do you prefered ?) , unfortunately i have to deploy my application on Tomcat. This is my study project, and i make this to become a Master of Techinal Univeristy ;), Deadline time is 30 th September :(
    greetings

  • How to run and compile a java servlet on Tomcat?

    Hi, I am very new to servlets in Tomact.
    I went to the java tutorial and from the address below I copy an example (SimpleServlet).I try to run and compile it in Tomcat, But I don't know how can I do that. I appreciate if somebody tell me the command line for compiling and running this example and the necassary steps. (My Tomcat is installed perfactly).
    http://java.sun.com/docs/books/tutorial/servlets/overview/simple.html
    Thankx

    Hello,
    I have the similar question.
    Instead of going thru sun's tutorial, I tried onjava's ("http://www.onjava.com/pub/a/onjava/2001/04/19/tomcat.html?page=1").
    I could see the jsp page, but when I tried to add a servlet, I got an error "Page not found". I followed exactly the same way they describe. The only thing I noticed was the resulting page on the tutorial had the URL of ".../servlet/...".
    Is this "servlet" directory something we are supposed to create our own? If so, under what directory? Or do we need to set up anything in order for the servlet to be referenced that way?
    Thanks in advance.

  • Servlets and Tomcat/Apache

    Okay,
    Tomcat 4.1 running with Apache.
    Installed mod_jk, piece of cake.
    JSPs run through Apache like a dream.
    Tomcat examples ( jsp and servlets) run through Apache perfectly ( that is no :8080 business).
    My JSP's run through Apache no problem. Works great.
    My SERVLETS WILL NOT RUN THROUGH APACHE FOR ANYTHING.
    My context looks like this in server.xml:
    <Context path="/nuweb" docBase="/home/shared/nuweb" debug="0"
    reloadable="true" crossContext="true">
    <Logger className="org.apache.catalina.logger.FileLogger"
    prefix="nuweb" suffix=".log"
    timestamp="true"/>
    </Context>
    Note: that I am not under <TOMCAT_HOME>/webapps.
    The reason is that I will, in production not be the Unix admin on the server. I will only have priviledges within my directory. I will not be able to drop war files in the webapps directory. I will not be able
    to start and stop tomcat or apache ( there are 100 diffrent apache contexts on that machine and someday many of them will be going through tomcat for jsp and servlet support).
    My servlets will only run if I put :8080/nuweb/servlet/HelloServlet in the URL. Take off the 8080 and I get Page not found. Not the tomcat 404 page, the Browswer 404 errror.
    Here is my web.xml which lives in the WEB-INF directory of of /home/shared/nuweb
    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE web-app
    PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
    "http://java.sun.com/dtd/web-app_2_3.dtd">
    <web-app>
    <servlet>
    <servlet-name>HelloServlet</servlet-name>
    <servlet-class>org.nu.servlet.HelloServlet</servlet-class>
    </servlet>
    <servlet-mapping>
    <servlet-name>HelloServlet</servlet-name>
    <url-pattern>/hello</url-pattern>
    </servlet-mapping>
    <servlet-mapping>
    <servlet-name>invoker</servlet-name>
    <url-pattern>/servlet/*</url-pattern>
    </servlet-mapping>
    </web-app>
    In devlopment I am on a system that is very close to what the production server will look like ( Tomcat 4.1 same version of Apache, same Unix ). In development I can restart all the servers edit server.xml etc. On the production I would have to schedule that stuff. I want to be able to compile classes and drop them in the WEB-INF/classes... directory and have them run. Is that too much to ask?

    Hi,
    I am also facing same error.
    I am not able to view my servlets via apache web server.
    ie when i do "http://localhost/enlighta/logon"
    I get http 404 page not found error
    but when I do http://localhost:8080/enlighta/logon
    all works fine
    I am using apache 2 and tomcat 4.5
    This is I have done:
    1.I have http server running on port 80
    2. appserver on port 8080
    3. I have a war file enlighta.war deployed on webserevr
    4. The static content like images and html page I have moved to webserver
    5. The servlet context of the app on the app server is /enlighta
    6. In the web.xml I have defined all the servlet maping.
    the port 8009 has the connecter is running/listening.
    the configuration
    sever.xml on tomcat
    <!-- Define an AJP 1.3 Connector on port 8009 -->
    <Connector port="8009"
    enableLookups="false" redirectPort="8443" protocol="AJP/1.3" />
    <Host name="localhost" appBase="webapps"
    unpackWARs="true" autoDeploy="true"
    xmlValidation="false" xmlNamespaceAware="false">
    httpd.conf on apache
    # Load mod_jk
    LoadModule jk_module modules/mod_jk.so
    # Configure mod_jk
    JkWorkersFile conf/workers.properties
    JkLogFile logs/mod_jk.log
    JkLogLevel info
    # First Virtual Host.
    <VirtualHost 192.168.1.2:8080>
    ServerAdmin [email protected]
    DocumentRoot /enlighta/
    ServerName localhost
    ErrorLog logs/enlighta_error_log
    TransferLog logs/enlighta_access_log
    JkMount /enlighta/* ajp13
    </VirtualHost>
    workers.properties
    worker.list=ajp13
    # Defining a worker named ajp13w and of type ajp13
    # Note that the name and the type do not have to match.
    worker.ajp13.type=ajp13
    worker.ajp13.host=localhost
    worker.ajp13.port=8009
    Now I feel I am doing something wrong on defining virtual host.
    Or may be something else is wrong.
    I have gone thru the previous thread but I dont have mod_jk.conf file.
    Please help!!!
    Thanks
    Sachin

  • Running servlets in tomcat server

    Hi,
    I am not able to execute servlets in tomcat,
    When i executed the program html file was running perfectly and when i click on the submit button it is displaying the following error
    type Status report
    message ServletCalled.class
    description The requested resource (ServletCalled.class) is not available.
    I followed the below procedure
    I created a new directory in webapps "webapps/test".
    Test directory contains
    1. callservlet.html file
    2. another directory Web-inf (i.e, webapps/test/Web-inf)
    Web-inf directory contains
    1. web.xml file
    2. another directory classes (i.e, webapps/test/Web-inf/calsses)
    classes directory contains
    1. ServletCalled.class file
    Html file code
    callservlet.html
    <html>
    <body>
    <form method=post action="/ServletCalled/ServletCalled.class">
    <input type=submit value="submit">
    </form>
    <body>
    </html>
    servlet file
    ServletCalled.java contains
    public void doPost(HttpServletRequest req,HttpServletResponse res ){
    java.io.PrintWriter out = req.getWriter();
    out.println("Hi, executed");
    web.xml file
    <?xml version="1.0" encoding="ISO-8859-1"?>
    <!DOCTYPE web-app
    PUBLIC "-//Sun Microsystems, Inc.//DTD Web
    Web Application 2.3//EN"
    "http://java.sun.com/dtd/web-app_2_3.dtd">
    <web-app>
    <servlet>
    <servlet-name>ServletCalled</servlet-name>
    <servlet-class>ServletCalled</servlet-class>
    </servlet>
    <servlet-mapping>
    <servlet-name>ServletCalled</servlet-name>
    <url-pattern>/ServletCalled</url-pattern>
    </servlet-mapping>
    </web-app>
    i used all the options above i changed the <url-pattern> and form tag to (<form action="/ServletCalled" method=get>)but same error persists
    Please help me out in this thanks in advance

    thanks !! i got the solution

  • Error in the Socket Communication between Java Client and VC++ Server

    In my application, using Java Client to do socket bi-communication with VC++ Server, which is done by somebody else.
    The error is after the application properly running one or two days, the VC++ Server cannot receive the messages passed by java Client, but at Java client, everything is the same, although using CheckError() after every print(), there is no exception thrown.
    The JVM is jdk1.3.1, platform is Win2k Server.
    The outputstream is PrintWriter().
    Please help me to settle down this problem. Thanks in advance.

    I read some thread in the forum, and found somebody had the similar problem with me. Just want to know how to settle this problem.
    In the client/server program. Client is a JAVA program and Server a
    VC++ program. The connection works, and the problem appears after some time. The Client sends a lots of requests to Serverm, the server seems receive nothing. But at the same time, the server is able to send messages to Client. The Client also can get the messages and handle them. Don't understand why there this problem and why it appears when it wants.
    The client is a Win2k platorm with JDK1.3.1 and the server is also a Win2K platform with VC++ 6.0.
    In the Client, using:
    inputFromServer = new BufferedReader(new InputStreamReader(socket.getInputStream()));
    outputToServer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(socket.getOutputStream())),true);
    Hope can get your help.

  • Socket Communication between java client and c++ server

    HI,
    In my project,I want to do the following:
    1.Sending datas from client to server.
    2.Getting the response from server to client.
    I written the client in java.but the server is in c++.
    Is it possible to communicate with the server using java codings itself?
    Im able to send the data from my java client to the server.
    but unable to get back the datas from server to client.
    Can anyone tell me how to do this?
    thanks a lot

    hi
    thanks for ur reply.
    I didnt get any error msg while getting the back the datas.
    Actually i divided my application into two parts.
    My application will act as both server and client.
    server ll get the browser request and send to the client and the client will send that data to the c++ server.
    Im able to do that.and unable to get the data from server.
    Didnt get any error.
    can u tell me how to make an application to act as both client and server.
    I think im wrong in that part.
    thanks a lot

  • SSL usage in JAVA servlet and JSP based web page

    I have several question to adjust security setting of my web page.
    First of all, When do we need SSL in web pages, are you advise to use this technique in medium level security needed web page which means no commercial data just information based..And Second question is if I need , How do I use SSL (secure socket layer) in my web page or what do I need to implement it in my JSP pages?
    My IDE is Websphere 5.0 and server is tomcat 4.1 and database server MS sql server 2000.
    Please don't answer my question with just giving URL's, try to explain me something detailed and supported with URL's and examples. I am just a beginner in security topics (specially SSL).
    If you help me, I am really appreciated.
    Thanks in advance.
    Ergin

    I have several question to adjust security setting of my web page.
    First of all, When do we need SSL in web pages, are you advise to use this technique in medium level security needed web page which means no commercial data just information based..And Second question is if I need , How do I use SSL (secure socket layer) in my web page or what do I need to implement it in my JSP pages?
    My IDE is Websphere 5.0 and server is tomcat 4.1 and database server MS sql server 2000.
    Please don't answer my question with just giving URL's, try to explain me something detailed and supported with URL's and examples. I am just a beginner in security topics (specially SSL).
    If you help me, I am really appreciated.
    Thanks in advance.
    Ergin

  • How to run the program of servlet in tomcat server

    I want to a java servelet program in Tomcat server.
    can any one guide me that how to do it.
    thanks

    Yes:
    http://jakarta.apache.org/tomcat/tomcat-5.0-doc/appdev/index.html
    Read the docs.

  • Differences between Java Servlet and Portlets

    Hello,
    May anyone let me know the differences between Java Servlet, JavaBeans and Portlets? It seems quite similar to each other... By the way, what are differences between a servlet container and portlet container? Thank you.
    Charoite

    JavaBeans are totally different from servlets or portlets. JavaBeans can be used in just about any environment. A JavaBean is basically a java class with a no-arg constructor which follows certain naming conventions for its get and set methods.
    Servlets can only function in an "web containers" which are provided by application servers which support servlets. The main function of servlets is to process requests (usually http requests) and generate output (usually web pages). They usually perform validation and other processing and then delegate the web page generation to a jsp.
    Portlets are similar to servlets but rather than generating an entire web page, their output is relegated to a portion of a page. A single web page may contain the output of several portlets. These portlets can communicate with each other. The portlet container provides the functionality to merge the output of the various portlets and the infastructure required to support the portlets.

  • Again problem with servlet and Tomcat

    My files are:
    webapps\greeting\src\GreetingServlet.java
    ................\index.html
    ................\WEB-INF\classes\GreetingServlet.class
    ........................\web.xml
    Url:http//:localhost:8080/greeting/ shows index.html but when i submit
    it showing
    HTTP Status 404 - /greeting/servlet/GreetingServlet
    type: Status report
    message: /greeting/servlet/GreetingServlet
    description: The requested resource (/greeting/servlet/GreetingServlet) is not available.
    Source code:
    1.index.html:
    <HTML>
         <HEAD>
              <TITLE>ProJava Registration</TITLE>
         </HEAD>
         <BODY>
              <H1>Welcome</H1>
              <FORM ACTION ="/greeting/servlet/GreetingServlet" METHOD= "POST">
                   <p>Your Name <INPUT TYPE= "text" SIZE= "40" NAME= "name" ></p>
                   <p>Your Email <INPUT TYPE= "text" SIZE= "40" NAME="email">
                   <INPUT TYPE= "submit" VALUE= "Submit" ></p>
              </FORM>
         </BODY>
    </HTML>
    2.GreetingServlet.java:
    import javax.servlet.* ;
    import javax.servlet.http.* ;
    import java.io.* ;
    import java.util.* ;
    public class GreetingServlet extends HttpServlet{
    protected void doPost (HttpServletRequest request,
                   HttpServletResponse response)
                        throws ServletException, IOException {
         String name = request.getParameter ("name");
         String email = request.getParameter ("email");
         String message = null;
         GregorianCalendar calendar = new GregorianCalendar();
         if (calendar.get(Calendar.AM_PM) == Calendar.AM) {
              message =" Good Morning";
         else {
              message = " Good Afternoon";
         response.setContentType("text/html");
         PrintWriter out = response.getWriter();
         out .println("<HTML>");
         out .println("<BODY>");
         out .println("<p>"+message +","+name+"</p>");
         out .println("<p> Thanks ("+email+")</p>");
         out .println("<p> -The Pro Java Team.</p>");
         out .println("</BODY>");
         out .println("</HTML>");
         out .close();
    Please help me
    Thanks in advance Also thanks to st.

    Hi,
    I think you have to change server.xml, which is in conf directory of your tomcat root directory.
    search context in server.xml
    and alter like this
    <Context path="/greetings" docBase="greetings" debug="0"
    reloadable="true" crossContext="true">
    Hope this will help
    Regards
    Sekhar

  • Related to Network program using Java Client and C server

    I am little bit experience in java technology. I need an urgent help as I have to submit a document related to C server and Java client. But while searching in net i cant get a proper guidance for C server as many errors thrown in sys/socket.h and other new header files. Can any one help me out for giving source code for C Server. so that i can further involve in that document. Please help me out. i am really helpless by the way the C server thrown error. after finishing that C server only i can concentrate on Java client...

    Hai Josah,
    Thanks for your reply.. I have gone through many sockets server program in C but the real proble is the header file they include like
    socket.h and in.h etc.. they also provide these header files but if we compile in turboC they inturn require some other header files. I dont get the full hierarchy of C server program. I found some help in Java programming Archive about C Server and java client. As i am new to C i cant get the full header files for the server.c if i complete taht only i can proceed to java client. If u can redirect me for any good C sites also i can be thankful for u forever..please

  • Need some project titles that can be done in java servlets and jsp or ejb

    I am final year cs engg student. I have completed course in java,j2ee. I have done the library management project in servlet. I need some project titles for my final year project. My interests includes, networking, desktop applications.

    Saish wrote:
    I'm not sure how to help other than to advise you will probably have the best success with something that interests you personally. You mention desktop applications and networking. Perhaps start with something Swing (or JavaFX) and perhaps use that to monitor a network, detect intrusions, dynamically load balance, etc. Really, it's whatever will stimulate you through a long project. If you have an idea in mind, but are having difficulties with how to come up with a spiffy title, then post more detail, and we can try and help.
    - SaishThanks Saish for your nice response.
    Whether It is possible to implement the cloud computing ? Is it possible ?

Maybe you are looking for