How is object handled with servlets?

Hi!
This is probably a very basic question, but I need to know. Does a servlet treat objects differently from any other Java class?
Consider you have the following class:
public class ClassC {
     private String strName = "John";
     public String getName() {
          return strName;
     public void setName(String name) {
          strName = name;
}Then we use a servlet to create a object of class ClassC:
     public void doGet(HttpServletRequest request, HttpServletResponse response)
               throws ServletException, IOException {
          String strFirstName= "Steve";
          ClassC c = new ClassC();
          c.setName("Lance");
          strFirstName = c.getName();
          response.setContentType("text/html");
          PrintWriter out = response.getWriter();
          out.println("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\">");
          out.println("<HTML>");
          out.println("  <HEAD><TITLE>A Servlet</TITLE></HEAD>");
          out.println("  <BODY>");
          out.println("strFirstName = " + strFirstName);
          out.println("  </BODY>");
          out.println("</HTML>");
          out.flush();
          out.close();
     } My question is what �out.println("strFirstName = " + strFirstName);� will print in a server on the webb?
Suppose you have a produced a ResultSet and you put that as a private variable in a class as in ClassC above. Suppose I use the same technique as in the doGet-method, and have methods that extract data from the ResultSet. Will each use user of the servlet get unique information or will every user get the same information?
I think (and hope) that each user will get unique information. Is this correct?
Regards
Jonas

As written... the object Class is local to to the doGet method. This means that each run of the doGet method gets its own instance of the object, and each user will get their own data.
If strFirstName or c was declared as a class member, then all users would get the same data (potentially):
//bad servlet:
  String strFirstName = "Steve";
  ClassC c;
  public void doGet(...) ... {
    c = new ClassC();
  }

Similar Messages

  • How can i handle with event, when i close a file (notped or word,excel..)??

    How can i handle with event, when i close a file (notped or excel...). i want do something..
    Edited by: Legy on Apr 21, 2008 11:45 PM

    of course notepad.exe is closed again as soon as the operating system has completed the process of loading its content into memory...
    And no "event" is fired when that happens, except maybe internal to the process that loaded the application to indicate that it's been loaded successfully and can now be executed.
    But there's no way your Java process is ever going to receive that notification.

  • How to use JNI with Servlets

    Hi
    i was trying to do some example with JNI. I can use JNI with standalone Java application but I just cannot figure out how I can use JNI with Servlet.
    Can some one show me a sample code using JNI with Servlets.
    thanks very much

    hi,
    I am also facing the same problem,
    when I am using JNI with stand alone application it works fine but when i tried to use it with a servlet It gives unsatisfied linker error
    stack: java.lang.UnsatisfiedLinkError: createSocket
         at RelayConnector.createSocket(Native Method)
         at RelayServlet.doGet(RelayServlet.java:70)
         at javax.servlet.http.HttpServlet.service(HttpServlet.java:740)
         at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
         at com.iplanet.server.http.servlet.NSServletRunner.invokeServletService(NSServletRunner.java:891)
         at com.iplanet.server.http.servlet.NSServletRunner.Service(NSServletRunner.java:458)
    It seems i have to do some path settings in my iplenet web server.
    If some one have faced the problem i would be glad to know the solution for this, i am literally bugged up,....

  • How iAS6.5 comply with Servlet API 2.3?

    Now , we have to deploy a new application using Servlet API 2.3 somewhere on iAS6.5 ,but we found that it is difficult . And we don't want to use Sun one 7 (iAS 7) yet .
    So , have a another way to be chosen to upgrade iAS6.5 to comply with Servlet API 2.3?

    No. iAS 6.5 is a servlet 2.2 container. If you want 2.3 features, you will have to upgrade to S1AS 7.0.

  • Object living with servlet/jsp container

    How do I make an Object live until the servlet container lives? I mean I want an Object to be instantiated once in the lifetime of the webserver session and its has to be singleton and should live alive until the webserver dies? How can I make this possible? I should be able to keep that object alive even if any no references are made to the object. Moreover I should be able to access that object from any java class on that webserver?

    You can't do this in memory. The easiest thing to do would be to read/write the persistant data you need from disk.
    Anything your JSP or servlet creates in memory will be cleared when it is done serving the request.

  • How Business Objects connects with Composite Studio 4.6.0

    Hi,
    Info on Composite:
    Composite Studio is third party tool which connects to multiple data sources and executes the scripts (similiar to VIEW) to retrieve the results. One has to make call to the scripts to get the results.
    more information: http://www.compositesw.com
    Requirement:
    Trying to connect BO XI R3.1 to composite as to call scripts to get data and then create Universe on the same.
    Connectivity should be JDBC or oriented towards Java (preference for Java but not mandatory)
    Tool: Composite Studio 4.6.0
    Driver: composite46.dll
    Driver location: C:\Program Files\Composite Software\CIS 4.6.0\apps\odbc
    Regards,
    Arjun Kushwaha
    Edited by: Arjun_Kushwaha on Nov 12, 2009 8:43 AM

    It will be great if you could let us know how to built the Universe on top of Composite, may be using ODBC connection.
    I tried by creating the user / system DSN but these connections doesn't appear when tried to create the Universe in designer (using BO XI 3.1)
    We can then try to build using JDBC connection.
    The data source is very scattered and Composite is in the position to handle them all and hence we cannot eliminate composite and are forced to use it as one of the underlying layer to connect to actual data.

  • Dialogs with servlets

    Hi
    Does anyone know how to use dialogs with servlets? I'd like to show a confirm dialog on the client machine. My first idea was to use JOptionPane.showConfirmDialog as such in the servlet, but then of course de dialog pops-up on the server side, and not on client side.
    Many thanks for the help,
    Nic

    You need to use javascript to confirm, ask questions, etc...
    You can see :
    http://www.webreference.com/programming/javascript/confirm/
    Or
    http://www.bodo.com/javacool.htm
    Fred

  • How to keep an application level object running with SunIDM?

    We are working on intergrate a gmail project with SunIDM. We need an application level object running with SunIDM so it will maintain a token generated from Gmail side. In anther servlet project, I had this object saved in the attribute of the ServletContext, then other session level servlet could share this attribute anytime. Is there a way to store attribute in Servlet Context and have it shared by different user session in SunIDM? I have been reading documents and searched this forum, haven't find any topics related how to maintain an application level object live. Hopefully that I can get some hint here.
    Thank you so much.

    Paul, Thank you so much for the further explaination. I don't think it will work since the token generated from gmail will expire every 24 hours.
    We are using the gdata library published from by gmail people, and I create a new UserService object and have it run in the application level. The UserService object will generate a token and renew it every 24 hours behind the scene. Here is how I implement it in my Servlet project:
    //to have a UserService object running at the application level:
    public class GmailUserService extends HttpServlet {
    public void init(ServletConfig config) throws ServletException{
    super.init();
    userService = new UserService(myApplication);
    config.getServletContext().setAttribute("gmailUserService", userService);
    //to access this UserService object from other servlet in each user session:
    UserService userService = (UserService)servletContext.getAttribute("gmailUserService");
    Gmail will trigger an error if we create a new UserService object for each user. They recommend to have all the user to share one UserService object. I am looking for similar approach in SunIDM.
    Thank you again, Paul, for trying to help.

  • Image scaling problem with object handles

    Hi,
    I am facing scaling problem.I am using custom actionscript component called editImage.EditImage consists imageHolder a flexsprite which holds
    image.Edit Image component is uing object handles to resize the image.I am applying mask to the base image which is loaded into imageholder.
    My requirement is when I scale the editImage only the mask image should be scaled not the base image.To achieve this I am using Invert matix .With this
    the base image is not scaled but it  is zoomed to its original size.But the base image should not zoomed and it should fit to the imageholder size always. When I scale the editImage only the mask image should scale.How to solve this.Please help .
    With thanks,
    Srinivas

    Hi Viki,
    I am scaling the mask image which is attached to imageHolder.When i  scale
    the image both the images are scaled.
    If u have time to find the below link:
    http://fainducomponents.s3.amazonaws.com/EditImageExample03.html
    u work with this component by masking the editImage.If u find any solution
    for scale only mask ,plz share the same.
    thanks,
    Srinivas

  • How do I pass an object to a Servlet?

    Hello,
    I have a fully initailized object called x.
    I need to invoke a servlet from an application and pass this object x to the
    servlet.
    This object contains all the necessary parameters which the servlet needs.
    How can I invoke a servlet from a class and pass this object?
    For Example:
    class SendObjToServlet
    try
    URL u = new URL("servlet_path");
    }catch(Exception e)
    Now how and where do I pass an object to this servlet??
    Please can any one respond?

    http://www.j-nine.com/pubs/applet2servlet/
    this website will give you the basic idea. It shows you how to do it with an applet the same idea will work for an applcation.
    lee

  • How to instance handler.java into servlet

    Hi
    I don't have much experience in servlet.
    I want to instance a handler.java which connects to database and has all sort of methods into a servlet. But I don't know how to do it as servlet is different from normal java files or jsp .
    Can anyone help?
    Thanks
    M

    A servlet is just a normal Java class and you can instanciate Objects in the Servlet like you would in any other Java class. That is import the class, declare the reference and then do a new on the class.
    The only caveat is that Servlets are multi-threaded so it is best to not have any class level objects unless they are thread safe.

  • How can we handle browser settings while dealing with the security ?

    Hi ,
    how can we handle browser settings while dealing with the security ?When we configured security in web.xml , during the first request the container is asking for the authentication credentials once they are provided it go's on. but when the user gives a fresh request from the second window within the same browser that time it is not asking for authentication. How can we overcome this.Is there anything to do with server configurations?
    How can we make the container no to keep the things or act like session?

    Ya... I am taking a small example need not happen always but a kind of possibility i am thinking off.
    once the user sign out and just left without closing the browser and a friend (suppose not a good friend ... just kidding...) of that user may open the same jsp or file .This time the security is breached. If that feature or property exists....
    I know what you might say ... the user will log-out before leaving where a programer might invalidate the session at the time of log out.
    Consider the case of a bad Programing or just a programer might forget to invalidate,At that time as a application administrator how can he solve that issue.
    Thanks.......
    Edited by: user8483670 on Jun 6, 2011 1:08 AM
    Edited by: user8483670 on Jun 6, 2011 1:09 AM

  • How can I run a servlet with Sun Java System Application Server PE 8?

    I've created a package with a TestServlet.class inside, used the deploytool to create a WAR and deployed this using the autodeploy folder.
    The filestructure has been generated and I find the TestServlet.class in
    [installdir]\domains\domain1\applications\j2ee-modules\testProject\WEB-INF\classes\[packagefolderstructure]\TestServlet.class.
    The context root is working fine, but I have no clue how I can run the servlet directly via the URL.
    I've tried many things like
    http://localhost:8080/testProject/TestServlet
    http://localhost:8080/testProject/servlet/TestServlet
    http://localhost:8080/testProject/servlet/[packagenamewithpoints]TestServlet
    http://localhost:8080/testProject/servlet/[packagenamewithslashes]TestServlet
    etc etc
    Can somebody tell me please how to write URLs to deployed servlets? Or send me an example url and xml descriptor files?
    Thanks a lot in advance!

    in web.xml use servlet mapping
    <servlet-mapping>
        <servlet-name>TestServlet</servlet-name>
        <url-pattern>/doit</url-pattern>
    </servlet-mapping>then use http://localhost:8080/testProject/doit

  • TS3694 Please how do I handle this. I downloaded a higher version of my Iphone 3 but during the installation it always hangs and show an error message that it cannot be downloaded with code1015.

    Please how do I handle this?
    I downloaded a higher version of my Iphone 3 but during the installation it always hangs and show an unknown error message that it cannot be downloaded and the code of the message 1015.

    This is usually a result of the iPhone being hacked with the cutsie term for that "jailbroken".
    http://support.apple.com/kb/TS3694#error1015
    Error 1015: This error is typically caused by attempts to downgrade the iPhone, iPad, or iPod touch's software. This can occur when you attempt to restore using an older .ipsw file. Downgrading to a previous version is not supported. To resolve this issue, attempt to restore with the latest iPhone, iPad, or iPod touch software available from Apple. This error can also occur when an unauthorized modification of the iOS has occurred and you are now trying to restore to an authorized, default state.

  • How do i set text in a object so that object expands with text and has even space on both sides of the object in illustrator cc?

    how do i set text in a object so that object expands with text and has even space on both sides of the object in illustrator cc?

    if you see all the different panel. I past the info in and have to manually expand the width of every panel. Is there a way of pasting the text in and the panel moves to the right with so that there is an even space on both sides of the blue panel?

Maybe you are looking for

  • How do you disable OS X (when you focus on a window) from auto-focusing on windows from the same (or similar) program on another screen

    Hi, I have what is quickly becoming a major nuisance, I hope someone here knows more than me (hopefully about to change this behaviour..?). Whenever I click on e.g. excel on one screen, the excel windows in the background on my other screen is automa

  • How to import a Flash Game in InDesign CS5 that will work?

    Hello, I created a simple drag n' drop game in Flash (AS 2.0) and have imported the SWF file in InDesign CS5. When testing it from InDesign Preview Panel, the game doesn't work properly (object drags but does not drop to target). Is there a way to im

  • Color picker problems

    I began having this problem in Leopard, (am now on Lion):  My color picker does not function - at all.  I can retrieve the color inspector, but the dropdown menu of the colors is non-functioning, I cannot select or use the magnifying glass feature. 

  • Lost Maps data in Memory Card

    I recently formatted my phone and memory card and lost the nokia maps data from the card. while updating with nokia suit it says "can't find maps on phone". what can i do for getting back the data ?  @fthab Attachments: maps.jpg ‏131 KB

  • Changing MRP profile of a material and sales order

    Hello, user has changed the MRP profile of some materials but now the sales order of the material has incosistency in Procurement Tab : indeed the procurement type is KSL and not in phase with the new MRP profile ( the procurement type must be KSV ).