Sharing info among servlet, output right??

hi everyone, i have written two servlet for sharing information, mean the information of one servlet can be shared by other. i have taken help from a book, but the desired output is not coming. can u please find what wrong with this 2 servlet.
This is the first servlet which will set the property of password to dingdong.
public class AttributeSetterServlet implements Servlet{
    public void init(ServletConfig config) throws ServletException{
        //bind object that is to be shared with other servlet
        ServletContext servletContext = config.getServletContext();
        servletContext.setAttribute("password", "dingdong");
    public void service(ServletRequest request, ServletResponse response) throws ServletException, IOException {
    public void destroy(){
    public String getServletInfo(){
        return null;
    public ServletConfig getServletConfig(){
        return null;
}THis is the second servlet which will get the attribute value, but the desired output is not coming. it will display different output.
public class DisplayAttributeServlet implements Servlet {
    ServletConfig servletConfig;
    public void init(ServletConfig config) throws ServletException{
        servletConfig = config;
    public void destroy(){
    public void service(ServletRequest request, ServletResponse response) throws ServletException, IOException {
        response.setContentType("text/html;charset=UTF-8");
        PrintWriter out = response.getWriter();
        ServletContext servletContext = servletConfig.getServletContext();
        Enumeration attributes = servletContext.getAttributeNames();
        while(attributes.hasMoreElements()){
            String attribute = (String) attributes.nextElement();
            out.println("Attribute name: " + attributes);
            out.println("\n");
            out.println("Attributes value: " + servletContext.getAttribute(attribute));
            out.println("\n");
    public String getServletInfo(){
        return null;
    public ServletConfig getServletConfig(){
        return null;
}

Ok I know that. Now what I meant is do I need to poll the server for new messages (still using the chat-app between midlets example) or can I make both midlets open a connection to the server and send their messages to the server, and have the server redirect the messages to the respective client-midlet. I'm thinking something like each client midlet opens a connection, sends stuff whenever it wants (on the server side, output streams are not closed until some special flag is set) and keeps listening for answers until the user quits or say some special char comes from the server.
The thing is I'm having some problems when I keep readStreams open after a while (inside a while loop waiting for some special code) and I was wondering if this is valid or is indeed a problem with my code.
This is what I meant with tunnel before, not really say raw socket comm between midlets but a tunnel through a server that nevertheless kept each midlet from having to poll the ditto all the time. Apologies for not being too clear about it.
I'm using something like (in pseudo pseudo-code & ommiting all the registration steps etc):
client midlets
conn = openConnection();
out = conn.getOutpuStream();
in = conn.getInputStream();
if (!postbox.isEmpty()) {
msg = removeHead(postbox);
out.writeStream( sendMessage(msg) );
... on a separate thread
while (USER_IS_ON){
msg = in.readStream();
if (msg != null) postbox.add(msg);
close(conn, out, in);
Server
out = request.getOutpuStream();
in = request.getInputStream();
data = in.readStream();
// write this guy's data on the other recipient's queue
queue.add(data, id);
... on a separate thread
while (USER_IS_ON){
// get data to this guy from queue
if (data = hasData(id) != null)
out.writeStream(data, id);
close(conn, out, in);
On fear of making this too long, I'll stop here. I can post the source if you wish but it is rather lenghty :-)
Thanks for the help!
cheers
j.

Similar Messages

  • I'm trying to set up Family Sharing. My settings show that the people I chose are there but I don't see any shared information. How do I access the shared info?

    I'm trying to set up Family Sharing. My settings show that the people I chose are there but I don't see any shared information. How do I access the shared info? All computers are using Yosemite 10.10.1 and are new 13" MacBook Pros.

    Hi wmcknigh,
    Welcome to Apple Support Communities.
    The article below should help you resolve the issue with shared content not appearing after setting up Family sharing on the MacBook Pros.
    If you don't see your family's shared content - Apple Support
    Cheers,
    -Jason

  • Need info on Billing Outputs

    Hello,
    I need info abt billing Outputs - The language is maintained in Bill to party (Customer master), Its maintained in Condition record, It can be changed while creating the invoice.
    Now my question is, which of the above three cases has got highest priority.
    Could some one provide me some info on this?
    Regards,
    Krishna

    By default, we will maintain language in Bill-to-Party & also Condition record. But if required, it can be chaged at Invoicing level while taking output. Priority will be Bill-to-party, followed by Condition Record.
    Regards,
    Rajesh Banka

  • Servlet output not displayed properly in Internet Explorer

    Hi All,
    I'm developing a servlet which uploads a file. After the servlet parses the request body, it stores the file contents as a binary string in the database. While displaying the contents of the attached file, the IE(Internet Explorer) is ignoring all the newlines and spaces. IThe same uploaded file when viewed through Firefox browser is being displayed properly. I've added some debug statements to print the filecontent before sending it to servlet output stream. They look exactly as they were in the uploaded file. The MIME type is application/octet-stream.
    I've also made the response to accept "ISO-8859-1" and "UTF-8" charsets, yet the IE is not rendering the file contents properly. The code looks like this,
    response.setContentType("text/html; charset= ISO-8859-1, UTF-8");
    byte[] buff = attachment.getAttachObject();
    OutputStream out = response.getOutputStream();
    out.write(buff);
    out.close();
    I've tried using PrintWriter also. I've tried changing the content types, character encodings of request and response objects, still couldn't resolve the issue. What really baffles me is that when it's displaying properly in Firefox, why can't it render properly in IE? I'm using Win XP SP2, and IE version is 6.0.29. The content which is being sent to the output stream contains newline and space characters, but they are not displayed in the browser. Did any one face this sort of issue? Your help is highly appreciated.
    Thanks,
    Tarun.

    Hi,
    Thanks for looking into the issue. Let me tell you that I've tried keeping various content-types like text/plain, text/xml etc, but in none of those cases the IE rendered the output properly. But with the same content-type i.e text/html or text/plain, Firefox is able to render the file content properly. I've tried a brutal force approach like below,
    response.setContentType("text/plain");
    PrintWriter out = response.getWriter();
    String str = new String(attachment.getAttachObject());
    char[] buff = str.toCharArray();
    for(i=0;i< buff.length; i++)
    int n = (int)buff;
    if(n == 10)
    out.println();
    else
    out.print(buff[i]);
    out.close();
    I was trying to print a newline whenever I find a newline character in the file content. Even this didn't work. Please suggest me some way to get rid of this problem.

  • Converting servlets output to PDF fle

    How to convert Java Servlets output html file to PDF file or a Word document.

    not sure what u mean by 'convert' the output to PDF or word document
    Do you mean you want to force the browser to open file using MSWord / PDF viewer? If yes :
    For showing output as a word document, you can set the servlet response MIME type to 'application/ms-word' and set its extension to .rtf . You can then use a RTF template to build servlet output (since RTF is flat file format). By replacing placeholder tags in RTF template, you can generate content.
    For showing output as PDF, you'll need some library for PDF writing.
    hth,
    Subodh

  • Need info on Invoice outputs

    Hello Folks,
    I need some info on Invoice outputs. In the condition records "Suffix1" (NAST-DSUF1) is maintained. Could some one let me know use of this field and if i want to create a new suffix, where it should be defined?
    Regards,
    Krishna

    Hi,
    For table you can refer the link provided by Ranjeet. The system check to print the pricing of the particular condition from Pricing procedure. Whatever condition you would like to print in your document, you have to flag 'X' or as per busine requirement in field P in the pricing procedure.
    Regards,
    AKT

  • Read Servlet output stream

    how can i read servlet output stream

    i m using SAX to create an XML.
    I set result to "Servlet Output Stream" as shown below :->
    SAXTransformerFactory saxTF = SAXTransformerFactory.newInstance();
    TransformerHandler th = saxTF.newTransformerHandler();
    Transformer t = th.getTransformer();
    StreamResult stRes = new StreamResult(res.getOutputStream());
    th.setResult(stRes);
    th.startDocument();
    what i want to wright the same xml result in file at the same time(parallel y).

  • Data sharing with cross servlet context

    Hello,
    Is it possible to share data between two servlet context?
    I tried to use RequestDispatcher to forward to another JSP from one context to other context. Before forwarding, I set some object in the destination context, and retrieved from the destination JSP, but it just raised ClassCastException ....
    // assume the current context is /test1
    ServletContext sContext = getServletContext().getContext("/test2");     
    RequestDispatcher dispatcher = sContext.getRequestDispatcher("/index.jsp");
    sContext.setAttribute("mybean", myBeanObj);
    dispatcher.forward(request, response);
    from the /test2/index.jsp, I tried to retrieved the value :
    MyBean bean = (MyBean)pageContext.getServletContext().getAttribute("mybean");
    and it raised "java.lang.ClassCastException"
    Please help !!
    Eric

    try {
    What about setting from a servlet that is loaded on startup and never called?
    catch () {
    Then what is the context for ;-)
    finally {
    What would be the best way to pass "global" constants among servlets?
    Thanks in advance.

  • Servlet Output Streams and clearing

    I am using servlets, and I want to be able to print something repeatedly. Well, that's not exactly true: I can print something repeatedly. Using a ServletOutputStream, it doesn't seem possible to clear what has already been written. Here's the code:
    import javax.servlet.*;
    import javax.servlet.http.*;
    import java.util.*;
    import java.io.*;
    public class AlwaysTime extends HttpServlet {
         public void doPost(HttpServletRequest req, HttpServletResponse res)                throws ServletException, IOException {
              HttpServletResponse oldRes = res;
              Date now = new Date();
              res.setContentType("text/html");
              ServletOutputStream out = res.getOutputStream();
              out.println("<html>");
              out.println("<head>");
              out.println("<title>Clock</title>");
              out.println("</head>");
              out.println("<body>");
              out.println("<h1 align=\"Center\">");
              out.println(now.toString());
              out.println("</h1>");
              out.println("</body>");
              out.println("</html>");
              try {
                 Thread.sleep(1000);
              } catch (InterruptedException ie) {}
              // Do nothing: wait for 1 second.
              doPost(req, oldRes);
         public void doGet(HttpServletRequest req, HttpServletResponse res)
              throws ServletException, IOException {
              doPost(req, res);
    }This code prints the time every second, but I want to clear the previous output stream. I thought the code shown above would work, but of course, oldRes points to the same object as res. But I don't know how to clear an output stream, so that it is completely empty. Instead, each of the new lines are appended to the same output stream.
    This doesn't only apply to servlet output streams: is there some way to clear the System output stream, for instance?
    But mainly the servlet output stream ...

    You would not want to use HTTP for this type of functionality. HTTP is known as a 'stateless' protocol that simply returns one exact response for each request. So, there is not way to 'clear' the stream (technically, you would not do so for 'normal' streams either, but when you add HTTP into the mix, the task is definitely not possible).
    You could implement the above using a RSS feed, or by using HTTP meta-refresh tags on the page itself ot resubmit the requests every second (though this would be inefficient). An applet would also do the task.
    - Saish

  • HT5622 I have given my old iphone to my daughter however cant seem to disconnect the two phones. I use icloud. What do i do to stop her using my email address, no for facetime, sharing info, contacts and photos????

    I have given my old iphone to my daughter however cant seem to disconnect the two phones. I use icloud. What do i do to stop her using my email address, no for facetime, sharing info, contacts and photos????

    To wipe phone
    Turn off imessage in settings/messages
    Turn off Facetime in settings/Facetime
    Delete icloud account in settings/icloud
    Erase all data and settings in settings/general/reset
    Delete the phone from your profile in https://supportprofile.apple.com if you registered your phone there

  • Shared utility class file among servlets and Ejb

    I have the following context:
    XXX.war:
    WEB-INF\
    Jsp files
    WEB-INF\classes\
    WEB-INF\lib\
    WEB-INF\web.xml
    WEB-INF\weblogic.xml
    YYY.jar
    META-INF\
    Class files
    META-INF\ejb-jar.xml
    META-INF\weblogic-ejb-jar.xml
    In XXX/WEB-INF/classes/…/Util.class
    In YYY/util.class
    How can I share Util.class between both XXX and YYY?
    Cheers,

    If you are on 8.1 check out
    http://e-docs.bea.com/wls/docs81/programming/classloading.html#1069420
    The larger document talks about how classloading works in Weblogic
    Dave
    <mehdi valizadeh> wrote in message news:[email protected]..
    I have the following context:
    XXX.war:
    WEB-INF\
    Jsp files
    WEB-INF\classes\
    WEB-INF\lib\
    WEB-INF\web.xml
    WEB-INF\weblogic.xml
    YYY.jar
    META-INF\
    Class files
    META-INF\ejb-jar.xml
    META-INF\weblogic-ejb-jar.xml
    In XXX/WEB-INF/classes/???/Util.class
    In YYY/util.class
    How can I share Util.class between both XXX and YYY?
    Cheers,

  • Sharing IPhoto among multiple users on ONE computer. Question about article

    http://docs.info.apple.com/article.html?artnum=304890
    Does anyone have an idea why the article doesn't mention using users/shared instead of creating a separate partition. It seems much easier, though from some of the other posts it looks like Permissions on users/shared may not work properly.
    This seems awfully complicated for the machine that advertises itself as easy to use. It was much easier to share files on Windows.

    I have followed the famous Apple article and have created a disk image with permissions ignored and the iphoto library in it. But in order to have the other user access the disk image, I have put it in the users/shared folder. As a result, when trying to access the library from the other user account, it says that I do not have enough rights to access the library. Any thoughts ?
    Thank you.
    Cesco

  • Shared objects in servlet?

    Consider this code snippet
    public class MyServlet extends HttpServlet {  
    //declare session object
    private HttpSession session;
    public void service(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException {
    session = req.getSession(true);
    // get a value
    String value_of_id = req.getParameter("some_name");
    session.setAttribute("myid",value_of_id);
    Now the question
    Will a new instance of servlet be spawned for each incoming request?
    Is the session object declared in servlet level shared among all servlet instances?
    If Yes, Is there a possibility that the value of 'my_id' for request#1 will be owerwritten by the value set from request#2?

    #1 - No servlets are multithreaded.
    So essentailly there is only instance but many threads processing a request?Correct.
    #2 - Yes All servlets and JSP's in the same servlet context can access a session.
    Will the servletcontext for servlet-thread#1 be the same as servletcontext for servlet-thread#2
    Yes. Servlet context is the webapp the servlets are running.
    http://localhost:8080/test/servlet/myServlet
    Here the context is /test.
    #3 - No. The servlet container assigns each session a unigue id so that each request will only access the session associated with requests from a specific browser.
    So essentially the concept of shared objects apply to Httpsession objects?
    When the servlet encounters request.getSession() it checks the request for a session cookie. It takes the session id from the cookie and retrieves the HttpSession object for that request. The servlet is multi threaded but each thread has it's own copy of the local variables so as long as you do not put the session object in a global variable each request will see a seperate session object. Therefore sessions are not shared objects.
    A request is a thread.

  • JSP sharing session among users

    Hey all,
    I got a simple but important problem to pass by you all.
    :-) I wrote an intranet application using jsp and servlets. The issue I found is at login, the userid displayed is from a prior session. For example, I login in the morning and then leave. Another user logs in in the afternoon and sees the userid field with my userid.
    I thought I would keep the value of the userid for each user, but it seems the server is keeping the session. I store the userid in a hash table and then store it in a HttpSession and pass the hash table around (much like a context). I thought HttpSession was unique for every user, so I figured GC would take out the prior session along with the data contained in it. Any ideas?
    I am in QA now and hope to be implemented by Tuesday. What I did to clear out the userid field was to remove the code that preloads that field from the session. It works, but it concerns me that maybe other data might be shared.
    Thanks,
    Patrick

    Session's are not shared across users. Actually
    sessions are mainitained by a variety of ways and one
    of the ways is cookies in the browser.
    If i understand you right , this problems occurs in
    the same machine and may be same instance of the
    browser.
    You might need to do the following...........
    1) Make the settings in your app server so that the
    session expires after some time. The session should
    not be active for ever.=== The session does time out after 30 minutes.
    2) Second is that have a login page and in that page
    always clean the session variable.=== I get the session from request.getSession(). Do === you call invalidate() on the HttPSession object to === initialize it or just session = null?
    3) Further make sure that none of the variable you use
    in the JSP is in application scope ie
    <%!
    int session_id
    %>
    In this example this variable is in application scope
    outside the jspservice function. And since the
    servlet(ie jsp) is called in multiple threads , you
    will get into the whole issue of synchronization and
    stuff. So be care about this scope ...
    === I know I don't use session ids. I see the need for === them, but not in the scope of this app.
    I think this would solve the problem.Thanks,
    Patrick

  • How can I convert the download.m4a and Info.plist into the right audio file

    The topic is actually the problem that I have.
    I have bought music and it was downloaded successful (all of it) but iTunes had a strange freeze while converting the files into the right audio file. Some files were converted but after the freeze no more.
    I'm now left with these .tmp folders in the downloads folder which have the download.m4a and Info.plist files.
    My iTunes is able to play these download.m4a files, but they show no information and covers and this is really annoying. I could write and change it all by myself, but than I would still miss some information (and covers).
    Is there any way for me to convert or combine these files?
    Note: I'm not able to restart any downloads, because they were successful.

    Hello ed2345,
    Thanks for the help, but this is not the problem.
    It's hard to describe the problem, but I'll try it again, this time with pictures.
    I was left with the following folders in the iTunes Downloads folder.
    http://www.picfront.org/d/7yb3
    These TMP Folders have a download.m4a and a Info.plist file.
    After moving the audio files in iTunes a bit I get this.
    http://www.picfront.org/d/7yb2
    As you can see no other Information for the download.m4a than the length.
    That's how the .m4p file looks like
    http://www.picfront.org/d/7yb1
    And this is how the same .m4a file currently looks
    http://www.picfront.org/d/7yb0
    Like I said, I could edit all these download.m4a files by myself but that would leave some information out.
    Note: Sorry, I hope the links do not spam you with annoying ads. I don't get any but I was told that there can be some annoying one.

Maybe you are looking for

  • ITunes U Browser Issues with Authentication

    We have had iTunes set up for a while and has worked well up until yesterday. If you click on the following link http://www.aacc.edu/sp/itunes/ifpod.cfm it will not work with IE. It only works with FireFox. I keep getting the following error: Error:

  • Pictures in a table

    Hi, I need to show a table, which has a picture (JPEG for example) in every entry, and to be able to choose one of the entries, so the activating program will know which entry has been chosen. what is the best way to implement it?

  • Select a region in plot

    I may need to select a region in a plot as the attached screenshot. When selecting it, a yellow or other color frame may appear. It can be rectangular or circle. After the selection, the frame may disappear. And I may get the frame's position paramet

  • Setting airport extreme MTU?

    a previous feed was closed before it was answered properly... strange regarding setting MTU to get the extreme to work. I managed that on my computer, in the location setting - ethernet - I put MTU down to 1392 according to the modem people (iburst i

  • After upgrade to 9.01 startup of firefox gives error message MOZCRT19.dll was not found

    After the upgrade to firefox 9.01 with windows xp I get every time firefox tries to launch the error message "This application has failed to start because MOZCRT19.dll was not found. Re-installing the application may fix this problem". Well, re-insta