Please help me to build a servlet within j2sdk1.4.and higher

somebody help me how to build a servlet and another javax technology

Try this code (and read its comments). If you need more help, don't hesitate explaining your problems or doubts
import java.io.*;  // To use PrintWriter object
import javax.servlet.http.*;  // To extend from HttpServlet
// To compile this class you have to include servlet.jar in the CLASSPATH variable
// To run this servlet you'll need a Servlet Container like jakarta-tomcat that
// you can download for free from http://jakarta.apache.org/tomcat/
// The simplest way to try this servlet is copying it into <TOMCAT_HOME>/webapps/examples/WEB-INF/classes directory
// Where TOMCAT_HOME is the folder where you have Tomcat installed, then open your browser
// and paste the following URL:  http://192.168.15.210:9090/examples/servlet/MyFirstServlet
public class MyFirstServlet extends HttpServlet {
    // Implements the doGet(...) method of the abstract class HttpServlet
    // This method will get the control of the execution if you "point" your
    // browser to this servlet or if you use the method GET in a HTML Form
    // setting the Form's "action" attribute to this servlet URL
    // That's something like <form name="frm" method="GET" action="http://yourhost:port/servlet/MyFirstServlet">
    public void doGet(HttpServletRequest request, HttpServletResponse response) {
        // Define the content type that your servlet is going to issue
        // You should use "text/html" if you are going to issue HTML code
        // You should use specific MIME-TYPES depending on your intended output
        response.setContentType("text/plain");
        try {
            // Get the response's PrintWriter to write to the output
            PrintWriter out = response.getWriter();
            // Print whatever you want.  This is going to be received}
            // by your browser.
            out.println("Hello world!");
        catch (IOException ioe) {
            System.out.println(ioe.getLocalizedMessage());
}

Similar Messages

  • PLEASE HELP!!! using servlet to generate an image in jsp page

    Hi,
    I am so stuck on this... please help.
    I have a servlet that generated a gif image dynamically. It uses a bean that stores the gif image in a byte array.
    The servlet outputs the byte data to the output stream. The code is really simple and looks like this:
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
            //HttpSession session = request.getSession();
            try {
                ServletOutputStream stream = response.getOutputStream();
                ImageByteInformation imageByteInfo = (ImageByteInformation) request.getAttribute("imageByteInformation");
                response.setContentType("image/gif");
                response.setContentLength(imageByteInfo.getByteData().length);
                stream.write(imageByteInfo.getByteData(), 0, imageByteInfo.getByteData().length);
                stream.flush();
            }catch( Exception e){   
                System.out.println("You are hooped!: " + e.getMessage() + " " + e.toString());           
            }When I redirect from the dispatch servlet straight to this servlet an image shows up in the browser window.
    However when I try to use this jsp page to display the image nothing happens...
    <%@page contentType="text/html" pageEncoding="UTF-8"%>
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
       "http://www.w3.org/TR/html4/loose.dtd">
    <html>
        <head>
            <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
            <title>JSP Page</title>
        </head>
        <body>
            <h2>Hello World!</h2>
            <img src="servlets/Map24ImageDisplayServlet"/>
             //I also tried src/servlets/Map24..., /src/servlets/Map24..., /display, servlets/display
            <h2>Did you see the image?</h2>
        </body>
    </html>My web.xml is here if it helps...
    <?xml version="1.0" encoding="UTF-8"?>
    <web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" 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">
      <display-name>HelloProject</display-name>
    <servlet>
        <display-name>ServletDispatcher</display-name>
        <servlet-name>ServletDispatcher</servlet-name>
        <servlet-class>servlets.ServletDispatcher</servlet-class>
      </servlet>
      <servlet>
        <display-name>Map24ImageDisplayServlet</display-name>
        <servlet-name>Map24ImageDisplayServlet</servlet-name>
        <servlet-class>servlets.Map24ImageDisplayServlet</servlet-class>
      </servlet>
      <servlet-mapping>
        <servlet-name>ServletDispatcher</servlet-name>
        <url-pattern>/hello</url-pattern>
      </servlet-mapping>
      <error-page>
        <error-code>404</error-code>
        <location>/404_error.html</location>
      </error-page>
      <servlet-mapping>
        <servlet-name>Map24ImageDisplayServlet</servlet-name>
        <url-pattern>/display</url-pattern>
      </servlet-mapping>
    </web-app>I can never get an image to come up. In fact I can never get the jsp page to run the servlet at all! HELP!!! What am I doing wrong?
    Thanks
    Edited by: Kind_of_Green on May 5, 2008 3:55 PM
    Edited by: Kind_of_Green on May 5, 2008 4:00 PM

    OK... so you WERE absolutely right about the src path for the image tag.
    However I also had another problem that was quite a bit more insidious and mostly just a symptom
    of how little I know about what goes on under the hood of a web app.
    My bean storing the image info was stored as a request attribute. When the servlet was called from the
    jsp page the request object was either reset or just never initialized. Anyway it is not the same request
    object I assumed it was being passed in the doGet method. I added my bean as a session
    attribute and everything is sparkly :)
    I can only assume that when a request is neither forwarded nor included (as is the case with
    calling the servlet from the img tag) it is disappeared.
    Anyway, thanks a mint man. I so totally appreciate your time.
    Ciao :)

  • Please help me to build the logic

    Hi All,
    Please help me to implement the following logic.
    The conditional statements should not only be executed in sequence, but also if any of them are true they should not be overridden by any subsequent conditional statements being true.
    When actual effort Accepted or Rejected for AST proposals and calculate a flag for “enhance to AST guideline” = Y/N as follows for each employee and display at the employee level
    1)If AST eligibility = N AND proposed AST % >0, then “N”
    2)Else If AST eligibility = N AND proposed AST % = 0 then “n/a”
    3)Else If AST eligibility = Y AND Act Rank = 3 AND proposed AST = 0 then “Y”
    4)Else If AST eligibility = Y AND Act Rank = 3 AND proposed AST >0 then “N”
    5)Else If AST eligibility = Y AND Act Rank = 2 AND proposed AST = 0 then “Y”
    6)Else If AST eligibility = Y AND AST % is greater than or equal to the AST guideline minimum AND less than or equal to the AST guideline maximum, then “Y”
    7)Else If AST eligibility = Y AND AST % is less than the minimum guideline OR greater than the maximum guideline, then “N”
    I tried the following code but I am not getting the expected result .
    Could you Please help me to build the logic.
    Your earliest response is very helpful to me.
    if (upper(P_stat)='ACCEPTED' or upper(P_stat) like 'REJECTED%') then
    else if NVL(P_elgi,'N') <> 'Y' AND P_prop > '0' then
    P_flag := 'N';
    else if(NVL(P_elgi,'N') <> 'Y' AND P_prop = '0') then
    P_flag := 'N/A';
    else if ((NVL(P_elgi,'N')='Y') AND P_rank = '3' AND P_prop = '0') then
    P_flag := 'Y';
    else if((NVL(P_elgi,'N')='Y') AND P_rank = '3' AND P_prop > '0') then
    P_flag := 'N';
    else if((NVL(P_elgi,'N')='Y') AND P_rank = '2' AND P_prop = '0') then
    P_flag := 'Y';
    Else if (P_prop >=ast_min_guide AND P_prop <= ast_max_guide ) then
    P_flag := 'Y';
    else
    ((P_prop < ast_min_guide) OR (P_prop > ast_max_guide)) then
    P_flag := 'N';
    end if;
    end if;

    Thanks for ur quick responce .
    When actual effort Accepted or Rejected for AST proposals and calculate a flag for “enhance to AST guideline” = Y/N
    Once the above condition is satisfied we have to check for remaing conditions
    if (upper(P_stat)='ACCEPTED' or upper(P_stat) like 'REJECTED%') then
    once it is satisfies then we have to go for remaing conditions.
    how can we do it in CASE statement.
    1)If AST eligibility = N AND proposed AST % >0, then “N”
    2)Else If AST eligibility = N AND proposed AST % = 0 then “n/a”
    3)Else If AST eligibility = Y AND Act Rank = 3 AND proposed AST = 0 then “Y”
    4)Else If AST eligibility = Y AND Act Rank = 3 AND proposed AST >0 then “N”
    5)Else If AST eligibility = Y AND Act Rank = 2 AND proposed AST = 0 then “Y”
    6)Else If AST eligibility = Y AND AST % is greater than or equal to the AST guideline minimum AND less than or equal to the AST guideline maximum, then “Y”
    7)Else If AST eligibility = Y AND AST % is less than the minimum guideline OR greater than the maximum guideline, then “N”
    I tried the following code but I am not getting the expected result .

  • Guys i need to get m itunes account unlocked its stopping mefor making in app purchases please help need to make a purchase within 30 minutes

    guys i need to get my itunes account unlocked its stopping mefor making in app purchases please help need to make a purchase within 30 minutes

    If you've tried to buy something and your've been charged for it (and it's not a temporary store holding charge) but haven't received it then try the 'report a problem' page to contact iTunes Support : http://reportaproblem.apple.com
    If the 'report a problem' link doesn't work then you can try contacting iTunes support via this page : http://www.apple.com/support/itunes/contact/- click on Contact iTunes Store Support on the right-hand side of the page, then Purchases, Billing & Redemption

  • PLEASE help!! I use Outlook for my email and the Mail App Icon in my dock was also storing all my emails. So, I tried to delete ONLY the emails in the Mail App but somehow (under Preferences maybe?) I also deleted all my emails in my Outlook inbox.

    PLEASE help!! I use Outlook for my email and the Mail App Icon that is in my dock, that I know nothing about, was also storing all my emails. So, I tried to delete ONLY the emails in the Mail App but somehow (under Preferences maybe?) I also deleted ALL my OUTLOOK emails in my inbox.  Can someone please please tell me if there is a way to get my Outlook inbox emails back OR EVEN the emails that were in my Mail app - because even tho I never use the Mail app, at least the emails would be there.
    When I was trying to delete the emails in my inbox for the Mail app - I followed THESE directions.  It did in fact clear my inbox for the Mail app.  But then I went to log on to my Outlook account and EVERY SINGLE EMAIL was gone.  And not in the Deleted box.  Just gone.  Here are the directions I followed that screwed everything up.  Please help.
    Top menu bar, Mail > Preferences > Accounts > Mailbox Behaviors.
    Uncheck "Store deleted messages on the server".
    At the drop list for "Permanently erase deleted messages when", choose "Quitting Mail".
    Next...
    Top menu bar, Mail > Preferences > General.
    At "When searching all mailboxes, include results from", uncheck "Trash".
    Select All = command A

    i found out my prob!
    here is what you do.
    go to the "system preferences" on your dock.
    click "software updates".
    click "installed software"
    if it shows something about a recent update about "EFI UPDATE, FIRMWARE, THUNDERBOLT" or anything like that, exit out of it.
    go to mail.
    click "mail" at the top.
    click "preferences...".
    find the account you are having trouble with, once you do, make sure its highlighted, then click the "-" at the bottom of the window (this will only effect that mail account, it will not effect your ical weather or not its synced thought that email account)
    hit the "+" (right next to the "-") and add your accout back!
    its something with that update that effected mail, i hope this works out for you, if not reply back

  • Please help to get onhand stock report with last purchase and billed date warehouse and item wise

    please help to get onhand stock report with last purchase and billed date warehouse and item wise

    Hi Rajeesh Ambadi...
    Try This
    SELECT distinct T0.ITEMCODE , t1.ItemName, T0.ONHAND as 'Total Qty',  
      T1.LASTPURDAT ,t1.LastPurPrc
    FROM OITW T0 INNER JOIN OITM T1 ON T0.ITEMCODE = T1.ITEMCODE
    INNER JOIN OITB T2 ON T1.ITMSGRPCOD=T2.ITMSGRPCOD left join ibt1 t3 on t3.itemcode = t0.itemcode and t3.whscode = t0.whscode
    WHERE
    T0.ONHAND>0
    AND T0.WhsCode ='[%0]'
    Hope Helpful
    Regards
    Kennedy

  • Whenever I connect my 4th generation iPod thouch, all of the playlists on my iPod get deleted. This is very frustrating. Someone please help me? I searched the settings on iTunes and couldn't find anything.

    Whenever I connect my 4th generation iPod thouch, all of the playlists on my iPod get deleted. This is very frustrating. Someone please help me? I searched the settings on iTunes and couldn't find anything.

    Also, when I go on to safari, another alert pops up that safari cannot verify the identity of the website, anything that I type in to as common as google.com. It gives me 3 options to either cancel, look at details, and continue. I've looked at the details of the website of Google and it is legitimate the site. Any help?

  • Someone please help me!!! updated my Mac Pro and random folders deleted.. please help!

    Please help me. I have osx 10.9.2. and very important folders just disappeared. Tryed installing recovery software, I'm NOT logged in as diff user (only my computer). Please help me. Apple said I unfortunately dont have phone support? but I think with their update I should get a little help. I hate apple so bad after this.. No problems with my computer ever until this bs. Please help me.

    macisgr8 wrote:
    I disagree, hard drives are a mechanical moving device- heating and cooling, facing power surges. I've installed many versions of Mavericks but never had a problem but I am willing to spend an extra 5 minutes cleaning up the hard drive.
    How many versions of Mavericks has there been? I have installed one. The only one I have ever seen. Then updated it twice. And never used Crapware like YASU or CleanMyMac or MacKeeper etc etc and have never had an issue. And i certainly would never recommend a program that even the developers say
    "In the testing I’ve done using Yasu on Mavericks, it has performed well, so I believe it’s okay to use Yasu on Mac OS 10.9.x. Of course, I have to provide the disclaimer that I can’t guarantee 100% compatibility… If you decide to use Yasu on Mavericks, you’re doing it at your own risk."
    Pete

  • Please help. I recently upgraded to IOS 8.2 and i realised that all my downloaded videos from itunes have somewhat vanished. I see the cloud sign with the downward arrow. However they won't play, i am being required to DOWNLOAD them again.

    Please help. I recently upgraded to IOS 8.2 and i realised
    that all my downloaded videos from itunes have somewhat vanished. I see the
    cloud sign with the downward arrow. However they won’t play, i am being
    required to DOWNLOAD them again. This is both in my iPhone and Ipad. Is there
    any other way to go around this? As I do not want to download a second time,
    that would cost me more money.

    Hello ogojohn,
    Thank you for using Apple Support Communities.
    The   icon indicates an item that is available for download. This is usually because it has been downloaded previously by the account you are logged in under and will not be charge again for the download. See the following article, while it references iTunes for Mac and not iOS, it is the same. 
    iTunes 12 for Mac: Download previous purchases from the iTunes Store
    Regards,
    Jeff D. 

  • My itunes will not! is giving me error7(windows error 126) and is stilling me MSVCR80.dll is missing and i tried downloading itunes like 6 times and is saying the same thing. Please help! i need to sync my kids ipads and ipods thank you!

    my itunes will not open! is giving me error7(windows error 126) and is stilling me MSVCR80.dll is missing and i tried downloading itunes like 6 times and is saying the same thing. Please help! i need to sync my kids ipads and ipods
    thank you!

    Follow the instructions of tt2 given in https://discussions.apple.com/thread/5822086

  • HT1937 I would like to help me. My iPhone was lost and stolen and I didn't have configured Find My iPhone. So I could n't find it. Please help me to find it or delete my information and photos. This is my serial No: DN*****TWD. Thank U

    I would like to help me. My iPhone was lost and stolen and I didn't have configured Find My iPhone. So I could n't find it. Please help me to find it or delete my information and photos. This is my serial No: DN*****TWD.  
    <Personal Information Edited by Host>

    If you didn't set up Find My iPhone, there's nothing we can do to help you. Sorry.

  • A few of my built in apps disappeared and I want them back, please help, a few of my built in apps disappeared and I want them back, please help

    a few of my built in apps disappeared and I want them back, please help, a few of my built in apps disappeared and I want them back, please help.  It just happened and I didn't do anything. 
    The camera app
    the I-tunes store
    the App Store
    and Safari all vanished. 

    Check Settings>General>Restrictions to be sure Camera, Safari and Installing Apps are set to On.  If they are check all your screens and inside all your folders.  If you still can't find it go to Settings>General>Reset>Reset Home Screen Layout.  This will restore the home screen to its original configuration but may move other apps around to do so.

  • HT1222 I have 10 gb more than what the update requires available and it still prompts that I don't have enough storage please help as I'm operating of of iOS 5 and I'm ready to smash my iPad

    I just purchased more storage and still prompts that I don't have enough storage please help as I'm operating of of iOS 5 and I'm ready to smash my iPad

    Have you tried doing the Update using iTunes on your Computer.?
    See the Using iTunes Section Here...
    How to update your iPhone, iPad, or iPod touch
    Make sure you have the Latest Version of iTunes (v11) Installed on your computer
    iTunes free download from www.itunes.com/download

  • Please help--I am trying to open a Gif file and can't manage it.  I was told to try iPhoto.  When I tried to open iPhoto, I could not without first upgrading it.  After doing this it still will not open.  Just this week I upgraded to Yosemite, I have

    Please help,  I am trying to open a GIF file and I am told it may be damaged or use a file format that preview does not recognize.  Is there another path I can take to be successful?      Many Thanks    John

    Please log out or restart the computer and try again.

  • I just bought iphone5 last 2 weeks.At first week i can use itune apps after these last 3 days i try to use itunes again and i couldnt open it...same as app store...please help me to solve my problem...thanks and god bless...

    i just bought iphone5 last 2 weeks.At first week i can use itune apps after these last 3 days i try to use itunes again and i couldnt open it...same as app store...please help me to solve my problem...thanks and god bless...

    Thanks Jakob. You are correct.
    I just finished another "experiment".
    I transcode the whole clip 1,2,3,4,5,6,7 to another ext Western Digital HDD and got the Error -50 too. Problem is this ext Western Digital HDD is Daisy chained to the LaCIe.
    So, I tried transcoding to another ext Western Digital HDD connected to my router. And this time NO PROBLEM.
    So, I should readjust the FW800 connectors.
    What do you mean by the controller of the Firewire ?
    Thanks
    Jakob Peterhänsel wrote:
    All I'm saying is, the error -50 from the Finder normally means there is something spooky going on.
    Here, the LaCie drives become unstable. In the few cases where I'v actually opened the cage and put the HDD into another mount, the HDD seems to be fine, so I suspect it's either the FW connectors of the controller itself.
    If the drive is under warranty, replace it, otherwise, move your data to another drive if it startes to do so frequently.
    Here, the drive will 'behave' normally for some time after a reboot of the OS, but it's a pain to reboot every X hours...

Maybe you are looking for