Calling a servlet in a HTML page

hi evryone,
I'm new to servlets so i'm trying to create some simple applications to understand how it all works. The thing i'm trying to do is calling a servlet in a HTML page. I've already installed a Tomcat web server and I've created a servlet called Hello.
public class Hello extends HttpServlet{
     public void doGet(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException{
          res.setContentType("text/html");
          PrintWriter out = res.getWriter();
          String name = req.getParameter("name");
          out.println("<HTML>");
          out.println("<HEAD><TITLE>Hello, " + name + "</TITLE></HEAD>" );
          out.println("<BODY>");
          out.println("Hello, " + name);
          out.println("</BODY></HTML>");
     public String getServletInfo(){
          return "testing servlet OK";
}In my HTML page I've written the follwing code:
<HTML>
<HEAD>
<TITLE>Just say hello</TITLE>
</HEAD>
<BODY>
<FORM METHOD=POST ACTION="../servlet/Hello">
What's your name?
<INPUT TYPE=TEXT NAME="name"><P>
<INPUT TYPE=SUBMIT>
</FORM>
</BODY>
</HTML>After running this HTML I get a text box and I thing I'm trying to do is, when I click on the button, the servlet will be loaded. However, the servlet can't be found and instead I get an error:
type Status report
message /servlet/Hello
description The requested resource (/servlet/Hello) is not available.
I suppose both file are in their approriate directories, but my class file still has the class extension. Do I need to change this? I hope that someone can help me.
Thanks in advance!

hi,
the servlet wasn't in a package, so I changed that. It seems that I get an other error now:
HTTP Status 503 - Servlet servlet/Hello is currently unavailable
type Status report
message Servlet servlet/Hello is currently unavailable
description The requested service (Servlet servlet/Hello is currently unavailable) is not currently available.
I still don't know what I may have forgotten, so i'm gonna resume what i have done till now.
the servlet: (Hello.class)
package servlet;
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class Hello extends HttpServlet{
     public void doGet(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException{
          res.setContentType("text/html");
          PrintWriter out = res.getWriter();
          String name = req.getParameter("name");
          out.println("<HTML>");
          out.println("<HEAD><TITLE>Hello, " + name + "</TITLE></HEAD>" );
          out.println("<BODY>");
          out.println("Hello, " + name);
          out.println("</BODY></HTML>");
     public String getServletInfo(){
          return "test servlet OK.";
}the HTML page (testServlet.html)
<HTML>
<HEAD>
<TITLE>Just say hello</TITLE>
</HEAD>
<BODY>
<FORM METHOD=GET ACTION="../servlet/Hello">
What's yoir name?
<INPUT TYPE=TEXT NAME="name"><P>
<INPUT TYPE=SUBMIT>
</FORM>
</BODY>
</HTML>the web.xml file
<?xml version="1.0" encoding="ISO-8859-1"?>
<!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>
  <display-name>Welcome to Tomcat</display-name>
  <description>
     Welcome to Tomcat
  </description>
<servlet>
<servlet-name>servlet/Hello</servlet-name>
<servlet-class>servlet/Hello</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>servlet/Hello</servlet-name>
<url-pattern>/servlet/Hello</url-pattern>
</servlet-mapping>
</web-app>paths of these files:
- Hello.class => D:\Tomcat 4.1\webapps\ROOT\servlet
- testServlet.html => D:\Tomcat 4.1\webapps\ROOT\more
( - web.xml => D:\Tomcat 4.1\webapps\ROOT\WEB-INF)
Thanks for your help!!!

Similar Messages

  • How to Call a WebDynpro application through html page.

    I have created a webDynpro application.How can i call this application through a html page?
    Thanks
    Pankaj Kumar

    Hi,
       You can add a link to your HTML page and set the anchor reference to the absolute URL of your WD application.
       The absolute URL of your WD application looks like
    http://<j2ee server>:<port>/webdynpro/dispatcher/<wd component name>/<application name>
       So your HTML code will look like:
    <a href="http://<j2ee server>:<port>/webdynpro/dispatcher/<wd component name>/<application name>">Link</a>
    Regards,
    Satyajit.

  • How to call KM content in independent HTML page?

    Hi,
    My requirement is to call KM contents in simple HTML page,
    Actually I want to show documents from specific location of KM into HTML page which is nowhere related to EP pages, it will be totally independent page.
    Can anyone come across the same requirements?
    Thanks,
    Vikas

    Hi,
    i think you can call KM content with in an independent HTML page by using the tags in HTML ,href="target path of your KM content" and target="_blank" OR "_new","_top" any of these you can use based on your requirement.But i think  you shud have to upload your html document under km content with in ur portal environment.As you  said your are not attaching that html page to portal  you can call your KM content by specifyng url of your km content, otherwise you can make use of quick link property of page. If you want further help you could ask me .. i hope it'll be useful for you.
    Regards,
    Sitara
    Edited by: sitara kola on Mar 7, 2008 11:47 AM

  • Servlets: Scrolling a html page

    I have a servlet that generates a page with edit buttons,
    rows, columns etc. When the edit button is pressed it
    allows the current row to be edited (hence the name edit button ;). The problem is, when I press a button way down on the bottom of the page (scrollable) it works as it should (opens a html textfield(?) on the row) but the drawback is, that the page is hiked up and you have to scroll down and find the edit row. So is there a way I can scroll it down automatically near the edit row?
    Thank you

    Have I understod correctly?
    When you press the button the servlet generates a new page with the textfield.
    You call the servlet something like this in the button: www.site.com/servlet/theServlet.
    Then call it as www.site.com/servlet/theServlet#here and insert <a name="here"> before the textfield in the generated page (in the servlet code).

  • Possible to make servlet look like html page?

    Is it possible to register a servlet so that it looks like an html page?
    for example the servlet "HelloWorld", I want to make it look
    like "HelloWorld.html".

    What you need to do is configure your web server / servlet engine to pass EVERY request for a .html file to a servlet. This is typically done by passing the requests to a router servlet, which then reads the request URI, and then instantiates a servlet based on the desired file name. Therefore, if your requests goes to "HelloWorld.htm", the router would instantiate the class "HelloWorld", probably by calling Class.forName("HelloWorld"), and then call its doService(), doPost(), or doGet() methods.

  • Can we Call a Servlet from a OA Page?

    Hi All
    My requirement is to call a servlet's doPost method from ProcessFormRequest.
    I have created one custom OA page. One submit button is there on OA page.When i click submit button it will go to controller's proessFormRequest method and from this method i have to call servlet's doPost method.
    Can we do that?
    Please Suggest
    Best Regards
    Majid

    Hi Majid,
    You can use the following method.
    pageContext.setForwardURL("ABC.jsp",
    null, // not necessary with KEEP_MENU_CONTEXT
    OAWebBeanConstants.KEEP_MENU_CONTEXT, // no change to menu context
    null, // No need to specify since we're keeping menu context
    hashmap, // params, // request parameters
    true, // retain the root application module
    OAWebBeanConstants.ADD_BREAD_CRUMB_NO ,// display breadcrumbs
    OAWebBeanConstants.IGNORE_MESSAGES );//
    Thanks
    Anoop

  • Call javascript function in an html page, how to?

    How can i call a javascript function in an html page were my flash catalyst swf is?

    I think you will need to import the catalyst fxp into flash or flash builder and add action script to invoke the javascript.
    These two links may be of use
    http://blog.codefidelity.com/?p=15
    http://www.switchonthecode.com/tutorials/flex-javascript-tutorial-simple-interaction
    I hope that helps

  • Fast Response Appreciated - Calling Edge Function from an HTML page embedded in iFrame within Comp

    This is a tricky one, but it may just be that I don't understand the syntax,
    Situation:
    I have an Edge Animate composition that is acting as an interface and container into which other content is embedded using an iFrame.  I have several functions in Stage > creationComplete, and for one of the embedded content pieces, I want to include a button that calls one of the Edge functions.
    Challenge:
    I have read about referencing elements within Edge when it is the Edge file that is embedded on an HTML page, but I cannot figure out how to reference Edge in the reverse.
    I have tried these options where headerselect(page) is my function:
    AdobeEdge.getComposition("EDGE-531849691").getStage().headerSelect("community");
    window.top.Edge.getComposition("EDGE-531849691").getStage().headerSelect("community");
    This is for a project that is time sensitive.  Your immediate help is greatly appreciated!
    Thanks!
    Fred

    Justin,
    Looks like someone has already responded to your post. Did that answer your
    question? In their suggestion, they indicated that you could actually
    created the jplayer instance within the Edge composition, and therefore
    have more direct access to its events. If that will not work for you, it
    may help to know how your page is laid out.  Where is the Edge file in
    relation to the jplayer and how do you intend for them to interact?  Does
    the player need to be outside of Edge for some reason?
    Let me know if you still need help. Thanks!
    Fred

  • Calling a servlet from a JSP page using the J2EE reference implementation

    I have a JSP with an include tag as follows: <jsp:include page="servlet/ConnectionServlet" flush="true" />
    When I use JRUN it works fine. I created an ear file and ported
    the application to the J2EE reference implementation. When running the app under the J2EE reference implementation the ConnectionServlet is never called. I figured it must a deployment issue. I tried adding the ConnectionServlet.class file to the WEB-INF\classes file as servlet\ConnectionServlet.class but the JSP still can't find the servlet. Any ideas where I've gone wrong? TIA, Joe

    I have a JSP with an include tag as follows:
    <jsp:include page="servlet/ConnectionServlet"
    flush="true" />Basically, WEB-INF/classes gets added to the classpath, so the directory structure under this folder should be identical to your package structure. If the ConnectionServlet.class is not actually in a package, then it should be directly in WEB-INF/classes (ie if "servlet" isn't actually the name of your package, don't use a WEB-INF/classes/servlet/" directory).
    Then try taking out the "servlet" from your include tag, so you just have page="/ConnectionServlet" (not sure about the leading slash - try experimenting!)
    if this doesn't work, try adding this to your WEB-INF/web.xml file:
    <web-app><!-- the web-app tags may already be there - don't add more -->
    <servlet>
    <servlet-name>ConnectionServlet</servlet-name>
    <servlet-class>your.full.package.here.ConnectionServlet</servlet-class>
    </servlet>
    <servlet-mapping>
    <servlet-name>ConnectionServlet</servlet-name>
    <url-pattern>/ConnectionServlet</url-pattern>
    </servlet-mapping>
    </web-app>
    Good Luck!

  • Calling a servlet in an ADFFaces pages

    Hi All,
    I have this code:
        public void handleReturn(ReturnEvent returnEvent) {
            // Add event code here...
             if (returnEvent.getReturnValue() != null)
               setLongAddressType( (Long) returnEvent.getReturnValue());
               //  System.out.println("Value from the dialog box: "+getLongAddressType().toString());
               FacesContext fctx = FacesContext.getCurrentInstance();
               ExternalContext ectx = fctx.getExternalContext();
               try {
                   ectx.redirect(((HttpServletRequest)ectx.getRequest()).getContextPath() +
                     "/selfMailerTranscript?id="+UserSystemState.retrieveUserId()+
                     "?addr="+getLongAddressType().toString() );
               catch (IOException e) {
                e.printStackTrace();
        }I runs the servlet and displays a PDF document. What I like it to do is bring the PDF up in a new window. We've done this using an a href tag like this:
    <jsf-layout:a href="#{facesContext.externalContext.requestContextpath}/servletNameHere" ...
    I'm looking for the ExternalContext method that will open a new window instead of redirect. Anyone know what that is?
    Thanks in advance,
    Dave

    Hello,
    Why not open a dialog(pop up) page.
    And put the code you provided in that separate dialog page?
    -Anton

  • 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

  • How to call a html page from servlet

    i want to link a servlet to a html page, if i use requestdispatcher, it says XXX.html is not available, can anybody help

    Can you be more specific about what you're trying to do? Can't read your mind =). But if you mean you want to just have an static HTML page such as a header read by the servlet you can you the requestdispatcher include().
    Create a servlet to generate a page, and then map it as /getPage in the web.xml file. Then you can use:
    // header
    RequestDispatcher rd = ...getRequestDispatcher("/getPage");
    rs.include(req, res);
    // the rest of the servlet output
    // and you can do another one for the footer down here
    rd = ...getRequestDispatcher("/getPageFooter");
    rs.include(req, res);
    and it'll output the HTML in the servlet.
    Hope this helps

  • How can I generate a html page in a servlet-applet connection?

    Hello, I have an applet which contains an ok button, when I click this button, I need that servlet generate an html page and view it in browser. How can I do this?
    Thanks

    But with this method only is possible I think open a page web, and if it is possible call url of the servlet, you generate other request and response object (other call to method doGet or doPost because ShowDocument needs parameter url), so the previously request when I click button ok it's no the same and how I obtain the prinwriter from first request, showDocument don't obtain html page from printwriter.

  • How can I display the HTML page from servlet which is called by an applet

    How can I display the HTML page from servlet which is called by an
    applet using the doPost method. If I print the response i can able to see the html document. How I can display it in the browser.
    I am calling my struts action class from the applet. I want to show the response in the same browser.
    Code samples will be appreciated.

    hi
    I got one way for this .
    call a javascript in showDocument() to submit the form

  • Servlet to call html page

    how would you publish html pages on the web. so far the html page that comes up is accessed from my hard drive ie it has H: in the URL address. can i avoid this happening?
    any help is very much appreciated.

    there is one other problem though. on the first html page there are 3 radio buttons and a submit button. depending on which radio button is selected, once the form is submitted it will take you to a particular html page.
    once submitted it goes to the servlet with the value and name of the chosen radiobutton.
    on the servlet side i have coded 'if' statements to identifiy which radio button has been chosen. from this it is to go to a sepcific page. however, from here i do i call the html page. the part of the code is below:
    if(value.equals("Lectures"))
    out.println("LECTURES");
    out.println("<HTML>");
    out.println("<HEAD><TITLE>Student's Information System</TITLE>");
    out.println("<script language=JavaScript><!--function methodRetrieve(){ document.myform.submit();}</script>");
    out.println("<script language=JavaScript><!--function methodEnterEdit(){ document.myform.submit();}</script>");
    out.println("</HEAD>");
    out.println("<BODY><FORM name=LECmyform METHOD=GET ACTION=http://brunhilde.dcs.qmul.ac.uk/~rkj1/tomcat/servlet/Lecture target=_top>");
    out.println("<H1><p ALIGN=CENTER>Lecture Attendance Records</H1>");
    out.println("Select one of the following:<BR><BR>");
    out.println("<SELECT name=subjectMenu>");
    out.println("<OPTION value=CS3>Computer Systems 3");
    out.println("<OPTION value=GUI>Graphical User Interface");
    out.println("<OPTION value=DLD>Digital Logic Design");
    out.println("<OPTION value=DRA>Decision Risk Analysis");
    out.println("</SELECT><BR><BR>");
    out.println("<INPUT TYPE=button name=theButton VALUE=Retrieve Attendance Records &gt><BR><BR>");
    out.println("<INPUT TYPE=button name=theButton VALUE=Enter/Edit Attendance Figures &gt><BR><BR>");
    out.println("</FORM></BODY></HTML>");
    this is just a rough html page but the actual page contains a lot more html and would be too silly to go about out.println it all in the servlet. is there a method that i can call from this if statement to call a html page?
    please help me if you can since i've been trying this for a while...
    thanks
    gina

Maybe you are looking for

  • Editor spot healing brush using slider to adjust size

    Is there anyway to make the "slider for size adjustment" more visible when using Editor Spot Healing Brush"? On my system, the slider bar is black and against the dark gray of the Editor Screen" it makes it very difficlt for me see it.

  • Audio cuts out randomly...known issue?

    Most Keynote presentations we record capture the entire audio of the person speaking just fine. However, random presentations will drop the audio with no rhyme or reason. Record it again and all is well. But this requires us to reschedule the trainer

  • Emailed PDFs automatically opening

    I've got a problem where, if I email PDFs to my gmail account and open them in mail on my iPad, it's automatically opening some of them (not all) in the message body. This is fantastically annoying, as I then don't get the option to open them in a se

  • Custom particle problem, transparency not showing in generated particles?

    Using After Effects CS5 and Trapcode Particular: I want to use a custom particle for the generated particles. So I have imported a .gif image of a pollen grain, which have a transparent backround. The transparency does not automagically show after th

  • Odd Wifi connection issue

    I have a Curve 8530 that will connect to wi-fi and connect to other hotspots. The problem is the browser insists that it is not connected to a router. This is false. I can connect to a site that I have previously been to (roosterteeth.com) and browse