Problems calling Java Servlets from HTML pages Online

Hello
I have created a Web site using Java Servlets, and have acquired some servlet enabled web-space however i am having some difficulty in calling the actual servlets from the HTML pages i was using the line of code as follows
http://localhost:8080/servlet/....
followed by the name eg.
http://localhost:8080/servlet/Login
however this doesn't seem to be working i have also tried using the exact address of the servlet but this didn't work either
i.e ..servlet/Login.java
I was wondering would anyone have any idea as in how the servlets should be called
Thanks very much

Once you write the Servlet code, you have to compile and put the classes in the server classpath. To refer these servlets from your pages, you have to configure them in the server configuration(typical a xml file). There you define how you are going to refer to the servlet(/servlet/Logon) and the correponding class.
-Mak

Similar Messages

  • How to call java program by HTML page

    Hi guys,
    I'm new java programer and want to build an HTML page to access to ORACLE database on NT server by JDBC, Can anyone give me a sample?
    I already know how to access database by JDBC, but I don't know how to call java program by HTML page.
    If you have small sample,pls send to me. [email protected], thanks in advance
    Jian

    This code goes with the tutorial from this web page
    http://java.sun.com/docs/books/tutorial/jdbc/basics/applet.html
    good luck.
    * This is a demonstration JDBC applet.
    * It displays some simple standard output from the Coffee database.
    import java.applet.Applet;
    import java.awt.Graphics;
    import java.util.Vector;
    import java.sql.*;
    public class OutputApplet extends Applet implements Runnable {
    private Thread worker;
    private Vector queryResults;
    private String message = "Initializing";
    public synchronized void start() {
         // Every time "start" is called we create a worker thread to
         // re-evaluate the database query.
         if (worker == null) {     
         message = "Connecting to database";
    worker = new Thread(this);
         worker.start();
    * The "run" method is called from the worker thread. Notice that
    * because this method is doing potentially slow databases accesses
    * we avoid making it a synchronized method.
    public void run() {
         String url = "jdbc:mySubprotocol:myDataSource";
         String query = "select COF_NAME, PRICE from COFFEES";
         try {
         Class.forName("myDriver.ClassName");
         } catch(Exception ex) {
         setError("Can't find Database driver class: " + ex);
         return;
         try {
         Vector results = new Vector();
         Connection con = DriverManager.getConnection(url,
                                  "myLogin", "myPassword");
         Statement stmt = con.createStatement();
         ResultSet rs = stmt.executeQuery(query);
         while (rs.next()) {
              String s = rs.getString("COF_NAME");
              float f = rs.getFloat("PRICE");
              String text = s + " " + f;
              results.addElement(text);
         stmt.close();
         con.close();
         setResults(results);
         } catch(SQLException ex) {
         setError("SQLException: " + ex);
    * The "paint" method is called by AWT when it wants us to
    * display our current state on the screen.
    public synchronized void paint(Graphics g) {
         // If there are no results available, display the current message.
         if (queryResults == null) {
         g.drawString(message, 5, 50);
         return;
         // Display the results.
         g.drawString("Prices of coffee per pound: ", 5, 10);
         int y = 30;
         java.util.Enumeration enum = queryResults.elements();
         while (enum.hasMoreElements()) {
         String text = (String)enum.nextElement();
         g.drawString(text, 5, y);
         y = y + 15;
    * This private method is used to record an error message for
    * later display.
    private synchronized void setError(String mess) {
         queryResults = null;     
         message = mess;     
         worker = null;
         // And ask AWT to repaint this applet.
         repaint();
    * This private method is used to record the results of a query, for
    * later display.
    private synchronized void setResults(Vector results) {
         queryResults = results;
         worker = null;
         // And ask AWT to repaint this applet.
         repaint();

  • Calling java class from jsp page

    Dear Friends.
    I wrote jsp page and java class.
    Am calling java class from jsp page. after processing result,
    I have to refresh jsp page from java class.
    processing time may take 5 minutes or 1 minute etc. that depends on user.
    Can It be possible ? if possible , How ?

    Ok, I get a very strange error now:
    org.apache.jasper.JasperException: Unable to compile class for JSPerror: An error has occurred in the compiler; please file a bug report (http://java.sun.com/cgi-bin/bugreport.cgi).
    What is this??? Anyone?

  • Problem while calling java function from html

    when i tried to call a java function from html i'm getting an error
    object don't support this property.
    what could be the reason.
    This is my html.
    I got this from this forum only.
    My applet is accessing the system property "user.home".
    I ran it in IE
    <DIV id="dvObjectHolder">Applet comes here</DIV>
    <br><br>
    <script>
    if(window.navigator.appName.toLowerCase().indexOf("netscape")!=-1){ // set object for Netscape:
         document.getElementById('dvObjectHolder').innerHTML = " <object ID='appletTest1' classid=\"java:test.class\"" +
    "height=\"0\" width=\"0\" onError=\"changeObject();\"" +
              ">" +
    "<param name=\"mayscript\" value=\"Y\">" +
    "<param name=\"archive\" value=\"sTest.jar\">" +
    "</object>";
    }else if(window.navigator.appName.toLowerCase().indexOf('internet explorer')!=-1){ //set object for IE
         document.getElementById('dvObjectHolder').innerHTML = "<object ID='appletTest1' classid=\"clsid:8AD9C840-044E-11D1-B3E9-00805F499D93\"" +
              " height=\"0\" width=\"0\" >" +
              " <param name=\"code\" value=\"test.class\" />" +
         "<param name=\"archive\" value=\"sTest.jar\">" +
              " </object>"
    </script>
    <LABEL id="lblOutputText">This text will be replaced by the applet</LABEL>
    <BR>
    <input value="Javascript to java" type=button onClick="document.appletTest1.fromJavaScript()">

    I tried this example using the repy given to an earlier post.
    But its not working with me.
    What i did in addition was adding plugin.jar to classpath to import netscape.javascript.*;
    Let me add some more details
    1) I'll add the stack trace
    2) my java progrma
    3) batch file to sign the applet.
    1) This is the stack trace i don't know whether u will undertand this
    load: class test.class not found.
    java.lang.ClassNotFoundException: test.class
         at sun.applet.AppletClassLoader.findClass(Unknown Source)
         at java.lang.ClassLoader.loadClass(Unknown Source)
         at sun.applet.AppletClassLoader.loadClass(Unknown Source)
         at java.lang.ClassLoader.loadClass(Unknown Source)
         at sun.applet.AppletClassLoader.loadCode(Unknown Source)
         at sun.applet.AppletPanel.createApplet(Unknown Source)
         at sun.plugin.AppletViewer.createApplet(Unknown Source)
         at sun.applet.AppletPanel.runLoader(Unknown Source)
         at sun.applet.AppletPanel.run(Unknown Source)
         at java.lang.Thread.run(Unknown Source)
    Caused by: java.io.FileNotFoundException: C:\FastranJava\AppletObject\bin\test\class.class (The system cannot find the path specified)
         at java.io.FileInputStream.open(Native Method)
         at java.io.FileInputStream.<init>(Unknown Source)
         at java.io.FileInputStream.<init>(Unknown Source)
         at sun.net.www.protocol.file.FileURLConnection.connect(Unknown Source)
         at sun.net.www.protocol.file.FileURLConnection.getInputStream(Unknown Source)
         at sun.applet.AppletClassLoader.getBytes(Unknown Source)
         at sun.applet.AppletClassLoader.access$100(Unknown Source)
         at sun.applet.AppletClassLoader$1.run(Unknown Source)
         at java.security.AccessController.doPrivileged(Native Method)
         ... 10 more
    Exception in thread "Thread-5" java.lang.NullPointerException
         at sun.plugin.util.GrayBoxPainter.showLoadingError(Unknown Source)
         at sun.plugin.AppletViewer.showAppletException(Unknown Source)
         at sun.applet.AppletPanel.runLoader(Unknown Source)
         at sun.applet.AppletPanel.run(Unknown Source)
         at java.lang.Thread.run(Unknown Source)
    2) Java Program
    import netscape.javascript.*;
    import java.applet.*;
    public class test extends Applet
         private JSObject win;
         private JSObject outputLabel;
         private boolean buttonFromJavaClicked=false;
         checkJavaScriptEvent evt=new checkJavaScriptEvent();
         public void init()
              try
                   evt.start();
                   win=JSObject.getWindow(this);
                   outputLabel=(JSObject)win.eval("document.getElementById('lblOutputText')");
                   outputLabel.setMember("innerHTML", "<center><h1>From Init<br>Your Home directory" + System.getProperty("user.home") + "</h1></center>");
              catch(Exception e)
                   e.printStackTrace();
         public void fromJavaScript()
              buttonFromJavaClicked=true;          
         public void fromJavaScript2()
              System.out.println("Started Form JavaScript2");
              try
                   String strLbl="<center><h1>From JavaScript<br>Your Homedir:" + System.getProperty("user.home") + "</h1></center>";
                   outputLabel.setMember("innerHTML", strLbl);
              catch(Exception e)
                   e.printStackTrace();
         class checkJavaScriptEvent extends Thread
              public void run()
                   while(true)
                        if(test.this.buttonFromJavaClicked)
                             System.out.println("OK buttonfromjava is true");
                             test.this.buttonFromJavaClicked=false;
                             fromJavaScript2();
                        try
                             Thread.sleep(3000);
                        catch(Exception e)
                             e.printStackTrace();
    3) Batch file
    del *.cer
    del *.com
    del *.jar
    del *.class
    javac -classpath ".;C:\Program Files\Java\jre1.5.0_06\lib\plugin.jar" test.java
    keytool -genkey -keystore harm.com -keyalg rsa -dname "CN=Harm Meijer, OU=Technology, O=org, L=Amsterdam, ST=, C=NL" -alias harm -validity 3600 -keypass password -storepass password
    jar cf0 test.jar *.class
    jarsigner -keystore harm.com -storepass password -keypass password -signedjar sTest.jar test.jar harm
    del *.class

  • Calling a servlet from HTML

    Is it possible to call a class/servlet from a front-end web page (web page is in HTML form not java form) given that I created my servlet to be executed per class? If there is, can you give me a sample code snippet on how to do this?
    An example on how I call a class in my servlet:
    coordinate c = new coordinate();
    boolean a = c.plot(x,y);
    //do somethingBackground:
    I have already finished creating the server side code for a website and I chose to call a class inside the doPost() method. The class called will be responsible for executing the logic.
    The problem arrives when the web designer created a webpage that requires more than 1 function to be called per page. Since I'm using doPost() which requires the form to be submitted, is there a way to know which submit button is clicked and thus execute the correct function?
    I have a plan that I can fall back to which is to change my code so that it will read variables from the URL instead of thru a method call, but it will take more time since there are a lot of methods. I just thought I ask here if there is a way to accomplish the above so that I can save my code from this mess.
    Thanks,

    My servlet is structured in a way that it calls a method with values that it acquires from the webpage. (The initial plan was to enclose the HTML inside a servlet, but was changed so now I need to incorporate my servlets/services inside the HTML)
    Like in my example, on the coordinate class x and y are acquired from input boxes located in the web page then invoked the method plot(x,y). Since it will be HTML main and servlet sub, I need a way to call plot(x,y) from an HTML page. Or are you saying that my option would be to just create an intermediary servlet that would acquire the input and then call my class to process.

  • Page length problem in PDFs generated from HTML pages in Acrobat

    I just spent an exhausting 2-1/2 hours on the phone with Adobe tech support (offshore) in order to get a 5 minute fix. I figured that I'd document it here in case another user has the same problem. (I'd checked the forums and a few e-mail lists and hadn't found a solution.)
    When generating PDFs from HTML (Web) pages, Acrobat squeezed all of the text into the middle of a single page (with just the last inch or so of text on page 2). This resulted in pages that Acrobat identified as being 30", 40", even 60" long, and the printed results were unusable. I haven't been able to identify an event or a system change that caused this to happen; Acrobat had been generating PDFs properly before this trouble started.
    THE FIX:
    1. Start Acrobat and run the Repair Installation option from the Help menu.
    2. Go to C:\Documents and Settings\user\Application Data\Adobe\Acrobat\8.0
    and rename the Preferences file to PreferencesOld. A PC restart will be
    required after this change.
    3. Restart Acrobat. This creates a fresh Preferences folder.
    4. Test creating PDFs from a single HTML page and from multiple pages.

    Thanks, Bernd, but where are these settings?  While I'm writing, is there a setting to make an html file fit on one page in Acrobat?

  • Problem calling java method from c

    Hi ,
    I'm trying to call a java method from a C program. it gives no error during compilation as well as building the application. but when i tried to create the JVM by running my application it pops up the message "The application failed to start because jvm.dll was not found. Re-installing the application may fix the problem." I tried out setting all the environment variables to include the jvm.dll(PATH set to c:\j2sdk1.4.2_05\bin;c:\j2sdk1.4.2_05\jre\bin). Still got the same message. Then i re-installed java platform once more. Even now i get the same error. I have more than one jvm.dll at locations jre\bin\client and server, oracle has some jvm.dll . Will that be a problem? if so can i remove those? which of them should be removed and how?
    The code i'm using is
    #include <stdio.h>
    #include <jni.h>
    #include <windows.h>
    //#pragma comment (lib,"C:\\j2sdk1.4.2_05\\lib\\jvm.lib")
    JavaVM jvm; / Pointer to a Java VM */
    JNIEnv env; / Pointer to native method interface */
    JDK1_1InitArgs vm_args; /* JDK 1.1 VM initialization requirements */
    int verbose = 1; /* Debugging flag */
    FARPROC JNU_FindCreateJavaVM(char *vmlibpath)
    HINSTANCE hVM = LoadLibrary("jre\\bin\\server\\jvm.dll");
    if (hVM == NULL)
    return NULL;
    return GetProcAddress(hVM, "JNI_CreateJavaVM");
    void main(int argc, char **argv )
    JavaVM jvm = (JavaVM )0;
    JNIEnv env = (JNIEnv )0;
    JavaVMInitArgs vm_args;
    jclass cls;
    jmethodID mid;
    jint res;
    FARPROC pfnCreateVM;
    JavaVMOption options[4];
    // jint (__stdcall pfnCreateVM)(JavaVM *pvm, void **penv, void *args) = NULL;
    options[0].optionString = "-Djava.compiler=NONE"; /* disable JIT */
    options[1].optionString = "-Djava.class.path=c:/j2sdk1.4.2_05/jre/lib/rt.jar"; /* user classes */
    options[2].optionString = "-Djava.library.path=lib"; /* set native library path */
    options[3].optionString = "-verbose:jni"; /* print JNI-related messages */
    /* Setup the environment */
    vm_args.version = JNI_VERSION_1_4;
    vm_args.options = options;
    vm_args.nOptions = 4;
    vm_args.ignoreUnrecognized = 1;
    JNI_GetDefaultJavaVMInitArgs ( &vm_args );
    pfnCreateVM = JNU_FindCreateJavaVM("jre\\bin\\server\\jvm.dll");
    res = (*pfnCreateVM)(&jvm,(void **) &env, &vm_args );
    // res = JNI_CreateJavaVM(&jvm,(void **) &env, &vm_args );
    /* Find the class we want to load */
    cls = (*env)->FindClass( env, "InstantiatedFromC" );
    if ( verbose )
    printf ( "Class: %x" , cls );
    /*jvm->DestroyJavaVM( );*/
    Could anyone help me solve this problem as early as possible, bcoz i'm in an urge to complete the project.
    Thanks in advance.
    Usha.

    You either have to add to the system path of where is your jvm.dll is located or explicitly link to jvm.dll call GetProcAddress to obtain the address of an exported function in the DLL.

  • Problem with return link from html page back to css page

    Here is the site..almost ready for publication
    http://www.matriley.com/glensite/index.html
    1) Go to properties for sale
    2)Choose a suberb
    3)click on a property with a video
    4) watch the crazy video if you like
    5) Click go back to properties
    ^) Yes the page is there but the property page is now
    inactive...why?
    8)The whole thing works fine on Firefox but we do have this
    Glitch on IE
    PLEAASSE Can someone help
    Regards Matthew [email protected]
    Everything works well but for the problem return link to the
    properties page after you have gone to the video.The property page
    becomes inactive

    Your page is a monster -
    Empty Cache
    10.6K 1 HTML/Text
    1.5K 1 Stylesheet File
    985.4K 25 Images
    997.7K Total size
    27 HTTP requests
    25 images with aggregate weight of ~1MB is much too large,
    you know?
    Anyhow, I cannot reproduce your problem in IE7. Are you
    referring to IE6,
    instead?
    Murray --- ICQ 71997575
    Adobe Community Expert
    (If you *MUST* email me, don't LAUGH when you do so!)
    ==================
    http://www.projectseven.com/go
    - DW FAQs, Tutorials & Resources
    http://www.dwfaq.com - DW FAQs,
    Tutorials & Resources
    ==================
    "fredbillmatt" <[email protected]> wrote in
    message
    news:fv0m9k$a7a$[email protected]..
    > Here is the site..almost ready for publication
    >
    http://www.matriley.com/glensite/index.html
    >
    > 1) Go to properties for sale
    > 2)Choose a suberb
    > 3)click on a property with a video
    > 4) watch the crazy video if you like
    > 5) Click go back to properties
    > ^) Yes the page is there but the property page is now
    inactive...why?
    > 8)The whole thing works fine on Firefox but we do have
    this Glitch on IE
    > PLEAASSE Can someone help
    > Regards Matthew [email protected]
    > Everything works well but for the problem return link to
    the properties
    > page
    > after you have gone to the video.The property page
    becomes inactive
    >

  • Problem calling Java method from JavaScript in JSP / ADF

    Hi all,
    In my JavaScript onMouseUp() function, I need to call a method on my Java backing bean. How is this done? Info on the web indicates a static Java method can be called by simply "package.class.staticMethod(...)". but when I put the statement
    "jsf.backing.GlobalRetriever.createBasemap(affectedLayer);"
    I get an error message "jsf is undefined".
    The functionality I'm trying to get is: I have a custom slider control and based on its value, I want to call oracle map viewer specifying a map extent of the (current extent / slider value) to do a zoom in/out. In addition, the slider uses a onMouseMove() function to change the size of the image display so it looks like a dynamic zoom in/out.
    Please assist or let me know if I can provide some additional information. Thanks in advance.
    Jim Greetham

    No. The Java and Javascript in a Faces application are really working in two different universes.
    Java is running on the server. It generates HTML (and sometimes even Javascript) and sends that to the client machine. That's where all your backing beans are.
    Javascript runs directly in the browser. There's no way anything on the server can have access to anything you define in Javascript, unless you explicitly send that information back to the server, either via standard form submission (which only works when someone presses a "Submit" button) or via an Ajax-type call. So otherwise, nothing you define in Javascript will ever be available to a backing bean.

  • Calling a function from HTML page

    I am using a mixture of jQuery Mobile and Edge Animate to build a mobile app.
    When I load the Edge file I need to also call a function in edge at the same time.
    How can I call a function that is inside the Edge Animate file from the container HTML file (jQuery button)?

    Here it is:
    sym.displayBAC = function() {
    // Set BAC once at begining so we can run the timer less often
    sym.currentToday=new Date();
    sym.currentHour=sym.currentToday.getHours();
    sym.currentMinute=sym.currentToday.getMinutes();
    sym.currentTime = sym.currentHour + (sym.currentMinute/60);
    if ( sym.currentTime < sym.startTime) {
    sym.currentTime = sym.currentTime + 24;
    else {
    sym.currentTime = sym.currentTime;
    sym.drinkingTime = sym.currentTime - sym.startTime;
    if (sym.drinkingTime > 24) {
    sym.reset();
    // convert mls to fluid ounces and multiply by alcohol percenatge
    sym.beerOunces = (sym.beerVolume * 0.033814) * sym.beerPercent;
    sym.wineOunces = (sym.wineVolume * 0.033814) * sym.winePercent;
    sym.spiritOunces = (sym.spiritVolume * 0.033814) * sym.spiritPercent;
    sym.champagneOunces = (sym.champagneVolume * 0.033814) * sym.champagnePercent;
    sym.premixOunces = (sym.premixVolume * 0.033814) * sym.premixPercent;
    sym.shotOunces = (sym.shotVolume * 0.033814) * sym.shotPercent;
    sym.cocktailOunces = (sym.cocktailVolume * 0.033814) * sym.cocktailPercent;
    sym.ciderOunces = (sym.ciderVolume * 0.033814) * sym.ciderPercent;
    // Total the alcohol in liquid ounces
    sym.totalOunces = sym.beerOunces + sym.wineOunces + sym.spiritOunces + sym.champagneOunces + sym.premixOunces + sym.shotOunces + sym.cocktailOunces + sym.ciderOunces;
    // Formula %BAC = (A x 5.14/W x r) - .015 x H
    sym.BAC = Math.round((((sym.totalOunces * 5.14) / (sym.weight * sym.ratio)) - .015 * sym.drinkingTime)*100)/100;
    //$.cookie("drinkingTime", sym.drinkingTime, { expires: 365, path: "/" });

  • Getting error when calling Java program from JSP page.

    Hi All,
    I'm getting below error msg, previously the page use to display and also java program use to run properly, but suddenly today i came across this error. May be some settings have been changed on my server, since number of developers uses this common webserver here.
    Any help would be much appreciated. Pls let me know if if anyone requires much info regarding this one.
    javax.servlet.ServletException: sun/tools/javac/Main
         at java.lang.Throwable.fillInStackTrace(Native Method)
         at java.lang.Throwable.fillInStackTrace(Compiled Code)
         at java.lang.Throwable.(Compiled Code)
         at java.lang.Exception.(Compiled Code)
         at javax.servlet.ServletException.(Compiled Code)
         at org.apache.jasper.servlet.JspServlet.service(Compiled Code)
         at javax.servlet.http.HttpServlet.service(Compiled Code)
         at org.apache.tomcat.core.ServletWrapper.doService(Compiled Code)
         at org.apache.tomcat.core.Handler.service(Compiled Code)
         at org.apache.tomcat.core.ServletWrapper.service(Compiled Code)
         at org.apache.tomcat.facade.RequestDispatcherImpl.doForward
    Root cause:
    java.lang.NoClassDefFoundError: sun/tools/javac/Main
         at org.apache.jasper.compiler.SunJavaCompiler.compile(Compiled Code)
         at org.apache.jasper.compiler.Compiler.compile(Compiled Code)
         at org.apache.jasper.servlet.JspServlet.doLoadJSP(Compiled Code)
         at org.apache.jasper.servlet.JasperLoader12.loadJSP(Compiled Code)
         at org.apache.jasper.servlet.JspServlet.loadJSP(Compiled Code)
         at org.apache.jasper.servlet.JspServlet$JspServletWrapper.loadIfNecessary(Compiled Code)
         at org.apache.jasper.servlet.JspServlet$JspServletWrapper.service(Compiled Code)
         at org.apache.jasper.servlet.JspServlet.serviceJspFile(Compiled Code)
         at org.apache.jasper.servlet.JspServlet.service(Compiled Code)
    Message was edited by:
    shukla_arvind

    did u happen to upgrade ur jdk?????

  • Tomcat 6 – Calling a  Java Servlet from a JSP Page

    Below is a very simple JSP Page that calls a Java Servlet. The question is given Tomcat security constraints, is it possible to call a servlet from a JSP and get the correct output without getting an error message? If so, how would you code the web.xml file?
    c:\apache-tomcat-6.0.18
    Under conf
    catalina
    localhost
    HelloWorldExample.xml is directly under localhost
    The application would have this directory structure:
    webapps
    HelloWorldExample
    hello.jsp is directly under HelloWorldExample
    Under HelloWorldExample
    src
    WEB-INF
    classes
    Under classes
    jservlets
    HelloWorld.java is in src folder
    HelloWorld.class is in jservlets folder
    HelloWorldExample.xml
    <Context path="/HelloWorldExample" docBase="HelloWorldExample" debug="0"
          reloadable="true" crossContext="true">    
    </Context>**************************
    hello.jsp
    <HTML>
    <HEAD>
    <TITLE>Hello</TITLE>
    </HEAD>
    <BODY>
    <FONT SIZE="4">
    <P>
    Please enter your name:
    <FORM 
       METHOD="Post"
       ACTION="servlet/jservlets.HelloWorld">
    <TABLE BORDER="3" CELLPADDING="1" WIDTH="100%" ALIGN="CENTER">
    <TR>
        <TD><B>Name:</B></TD>
        <TD><INPUT TYPE="text" NAME="Name" VALUE="" SIZE="65"> </TD>      
    </TR>
    </TABLE>
    <P>
    <INPUT TYPE="SUBMIT" VALUE="Submit">
    </FORM>
    </FONT>
    </BODY>
    </HTML>******************
    HelloWorld.java
    package jservlets;
    import java.io.*;
    import java.util.Date;
    import java.util.*;
    import java.text.*;
    import java.sql.*;
    import javax.servlet.*;
    import javax.servlet.http.*;
    public class HelloWorld extends HttpServlet
       PrintWriter out;
       PrintWriter err; 
       String strName;
    public void displayMessage(HttpServletRequest request, HttpServletResponse response)
          throws Exception
             try
                if (!strName.equals("") && strName != null)
                   out.println("Hello " + strName + "" + "<P>");
                    out.println("Hello World" + "<P>");
                else
                    out.println("Hello World" + "<P>");
            catch (Exception e)
                out.println("Exception: Could not display message." + "<P>");
                err.println (e.getMessage () ) ;
                out.println("<P>");
    public void doPost(HttpServletRequest request, HttpServletResponse response)
               throws ServletException, IOException
          try
               response.setContentType("text/html"); 
               out = response.getWriter();
               err = response.getWriter();
               strName = request.getParameter("Name").trim();
               out.println("<html><head><title>");        
              out.println("</title></head><body>");
               out.println("<FORM");
               out.println("METHOD=POST");
               out.println("ACTION=http://localhost:8080/HelloWorldExample/hello.jsp>");
             out.println("<TABLE ALIGN='RIGHT'>");
             out.println("<TR>");
             out.println("<TD>");          
               out.println("<INPUT TYPE=\"SUBMIT\" VALUE=\"Hello World Page\";>");
               out.println("</INPUT>");
              out.println("</TD>");
             out.println("</TR>");
             out.println("</TABLE>");
             out.println("</FORM>");
             out.println("<BR CLEAR='all'>");
               out.println("<P>");        
               displayMessage(request, response);
               out.close();
             out.println("</body></html>");               
           catch(Throwable e)
              e.printStackTrace();
          public void doGet(HttpServletRequest request, HttpServletResponse response)
             throws ServletException, IOException
             doPost(request, response);
    web.xml
    <servlet>
          <servlet-name>HelloWorld</servlet-name>
          <servlet-class>jservlets.HelloWorld</servlet-class>
    </servlet>  
    <servlet-mapping>
            <servlet-name>HelloWorld</servlet-name>
            <url-pattern>/servlet/HelloWorld</url-pattern>
    </servlet-mapping>      ******************************
    HelloWorld.java can be compiled by using javac.
    Once compiled, HelloWorld.class would be moved to the jservlets folder.
    FYI, coding the above url-pattern results in:
    HTTP Status 404
    The requested resource (/HelloWorldExample/servlet/jservlets.HelloWorld) is not available
    The following url-pattern in the web.xml file permits the servlet to be executed but results in a null pointer exception:
    <servlet-mapping>
            <servlet-name>HelloWorld</servlet-name>
            <url-pattern>/ </url-pattern>
    </servlet-mapping>      **************************************************
    Robin

    This problem was resolved.
    In hello.jsp
    ACTION="servlet/jservlets.HelloWorld">
    was replaced with
    ACTION="servlet/HelloWorld">
    Robin

  • Calling a servlet from java

    How to call a servlet from java?
    your help is greatly appreciated..

    Welcome to the forum
    You seem to be misunderstanding something. Do some googling to learn what you need about servlets. Simplified, servlets are java code that's hosted by a web container, such as Tomcat. When a servlet gets called as a consequence of someone requesting a url from the container, it takes in a request object and a response object. All the magic is then in creating an appropriate response (e.g. html) for the incoming request.

  • Calling a servlet from a Java Stored Procedure

    Hey,
    I'm trying to call a servlet from a Java Stored Procedure and I get an error.
    When I try to call the JSP-class from a main-method, everything works perfectly.
    Java Stored Procedure:
    public static void callServlet() {
    try {
    String servletURL = "http://127.0.0.1:7001/servletname";
    URL url = new URL(servletURL);
    HttpURLConnection conn = (HttpURLConnection)url.openConnection();
    conn.setDoOutput(true);
    conn.setRequestProperty("Pragma", "no-cache");
    conn.connect();
    ObjectInputStream ois = new ObjectInputStream(conn.getInputStream());
    Integer client = (Integer)ois.readObject();
    ois.close();
    System.out.println(client);
    conn.disconnect();
    } catch (Exception e) {
    e.printStackTrace();
    Servlet:
    public void doGet(HttpServletRequest request, HttpServletResponse response)
    throws ServletException, IOException {
    Integer id = new Integer(10);
    OutputStream os = response.getOutputStream();
    ObjectOutputStream oos = new ObjectOutputStream(os);
    oos.writeObject(id);
    oos.flush();
    oos.close();
    response.setStatus(0);
    Grant:
    call dbms_java.grant_permission( 'JAVA_USER', 'SYS:java.net.SocketPermission','localhost', 'resolve');
    call dbms_java.grant_permission( 'JAVA_USER','SYS:java.net.SocketPermission', '127.0.0.1:7001', 'connect,resolve');
    Package:
    CREATE OR REPLACE PACKAGE pck_jsp AS
    PROCEDURE callServlet();
    END pck_jsp;
    CREATE OR REPLACE PACKAGE BODY pck_jsp AS
    PROCEDURE callServlet()
    AS LANGUAGE JAVA
    NAME 'JSP.callServlet()';
    END pck_jsp;
    Architecture:
    AS: BEA WebLogic 8.1.2
    DB: Oracle 9i DB 2.0.4
    Exception:
    java.io.StreamCorruptedException: InputStream does not contain a serialized object
    at java.io.ObjectInputStream.readStreamHeader(ObjectInputStream.java)
    at java.io.ObjectInputStream.<init>(ObjectInputStream.java)
    The Servlet and the class work together perfectly, only when I make the call from
    within the database things go wrong.
    Can anybody help me.
    Thank in advance,
    Bart Laeremans
    ... Desperately seeking knowledge ...

    Look at HttpCallout.java in the following code sample
    http://www.oracle.com/technology/sample_code/tech/java/jsp/samples/jwcache/Readme.html
    Kuassi

  • Get parameters from html page from java application standalone ...

    Hi all,
    I work in one solution that i have values in Html Page and i want get the parameters values from html and cath they in java application standalone.
    The Html page is in same host than de java application.
    I want know if this is possible. I wnat know if without HttpServlet i can get the parameters from Html Page pure.
    Thanks in Advance for the ideas,
    Antonio.

    Hi Abdul,
    The problem is my client want one solution where i have one page simple page Html and one application java standalone. This application runs in one machine, but we don't have web server. So the question is: Is possible without web server i can get the parameters values that is inside the html page from java application. I remember you that the application java is one .jar that run's with one command line from crontab "java -jar teste.jar".

Maybe you are looking for