Can servlet be serialize

hi all,
i wanna discuss some this. can i serialize a servlet.
thanks
Ravi

Off course you can, the only thing you should ask youself is wheather it makes sense or not to do it.
MeTitus

Similar Messages

  • Can servlet access Serializable Bean ?

    This is my bean below.. My jsp pages can access this bean but my servlet cannot... Do I need to make remove the Serializable interface that I am implementing right now so servlet can access ? Can serlvet access beans ?
    import java.io.*;
    import java.sql.*;
    import javax.sql.*;
    import java.util.*;
    * Re-usable database connection class
    public class ConnectDB implements Serializable{
    // setup connection values to the database
    static final String DB_DRIVER = "";
    static final String myURL = "";
    static final String USERNAME = "";
    static final String PASSWORD = "";
    static Connection con = null;
         public ConnectDB(){}
         /* Returns a connection the file that calls the method*/
         public static Connection getConnection()
              try
                   Class.forName("oracle.jdbc.driver.OracleDriver");
                   con = DriverManager.getConnection("......");
              catch (Exception e)
                   e.printStackTrace();
              finally
              return con;
         /*Closes Connections*/     
         public static void closeConnection(Connection con)
              try
                   if (con != null)
                   con.commit();     
                   con.close();
              catch (Exception e)
                   e.printStackTrace();
    }

    A Servlet is just a Java class and so can access beans. Also, a JSP is translated to a servlet before execution so you already have a servlet accessing the bean.
    Can you post relevant code and error message?

  • Can Servlet embed flash??

    hi,all
    Recently,I've start write servlet code,and client UI which use flash application.But I have problem with write out page through servlet.
    I want to know can servlet embed flash (swf.file).Below I post some section of my code.
    protected void doGet(HttpServletRequest request, HttpServletResponse response)
    throws ServletException,IOException
    response.setContentType("text/html");
    PrintWriter out = response.getWriter();
    out.println("<html>");
    out.println("<head>");
    out.println("<meta http-equiv=Content-Type content='text/html>");
    out.println("<title>XXX</title>");
    out.println("<script language='JavaScript'>");
    out.println("function openNewWindow(URLtoOpen, windowName, windowFeatures){");
    out.println("newWindow=window.open(URLtoOpen, windowName, windowFeatures); } </script>");
    out.println("<script language='JavaScript' type='text/JavaScript'>");
    out.println("<!-- ");
    out.println("function setFlashVars() {");
    out.println("enterprise.SetVariable('userid'," + UserID + "); }");
    out.println("function openBrWindow(theURL) {");
    out.println("window.open(theURL,'desc','width=588,height=285'); }") ;
    out.println("//--> </script>");
    out.println("</head>");
    out.println("<BODY bgcolor='#999999' onLoad=\"setFlashVars()\">");
    out.println("<A HREF=javascript:top.close()></A> <A HREF=e-date.swf></A> <!-- text used in the movie-->");
    out.println("<OBJECT classid=\"clsid:D27CDB6E-AE6D-11cf-96B8-444553540000\" codebase=\"http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0\" WIDTH='100%' HEIGHT=\"100%\" id=\"enterprise\" ALIGN=\"\">");
    out.println("<PARAM NAME=movie VALUE=\"enterprise.swf\">");
    out.println("<PARAM NAME=quality VALUE=high>");
    out.println("<PARAM NAME=scale VALUE=exactfit>");
    out.println("<PARAM NAME=devicefont VALUE=true>");
    out.println("<PARAM NAME=bgcolor VALUE=#999999>");
    out.println("<PARAM name=flashvars value=\"gatewayURL=" + gatewayURL + "&Userid=" + UserID + "&Today=" + today + "\">");
    out.println("<EMBED src=\"enterprise.swf\" quality=high scale=exactfit devicefont=true bgcolor=#999999 WIDTH='100%' HEIGHT='100%' NAME=\"enterprise\" ALIGN=\"\" TYPE=\"application/x-shockwave-flash\" flashvars=\"gatewayURL=" + gatewayURL + "&Userid=" + UserID + "&Today=" + today + "\" PLUGINSPAGE=\"http://www.macromedia.com/go/getflashplayer\"> </EMBED>");
    out.println("</OBJECT>");
    out.println("</BODY>");
    out.println("</html>");
    out.close();

    You should use the path to the .swf file, i.e. /myapp/flash/whatever.swf

  • Can servlet has more than one init method...?

    Clarification 1:
    Suppose i will write init()(-without constructor) method. In this case, how servlet config object passed to init method.
    Clarification 2:
    if i will override init(ServletConfig) .why do i need to call super.init(config).
    thanks,
    JaiGaneshR

    suppose i ll override init method without constructor. //wrong
    i think u want.
    suppose i ll override init method without arguments
    then also servlet calls the init(ServletConfig) method.
    1st servlet container check in ur Servlet class for init(ServletConfig)
    it's not found.
    2.then it checks in the super class HttpServlet. it's not found.
    3.then it checks in the super class GenericServlet there it will found it.
    then it will execute.
    package javax.servlet;
    import java.io.IOException;
    import java.io.Serializable;
    import java.util.Enumeration;
    // Referenced classes of package javax.servlet:
    // Servlet, ServletConfig, ServletException, ServletContext,
    // ServletRequest, ServletResponse
    public abstract class GenericServlet
    implements Servlet, ServletConfig, Serializable
    public GenericServlet()
    public void destroy()
    public String getInitParameter(String name)
    return getServletConfig().getInitParameter(name);
    public Enumeration getInitParameterNames()
    return getServletConfig().getInitParameterNames();
    public ServletConfig getServletConfig()
    return config;
    public ServletContext getServletContext()
    return getServletConfig().getServletContext();
    public String getServletInfo()
    return "";
    public void init(ServletConfig config) *<-------------------------------------------------- called*
    throws ServletException
    this.config = config;
    init(); ---------------------------------------------------> called your override method
    public void init() *<------------------------------------------------- Not called*
    throws ServletException
    public void log(String msg)
    getServletContext().log(getServletName() + ": " + msg);
    public void log(String message, Throwable t)
    getServletContext().log(getServletName() + ": " + message, t);
    public abstract void service(ServletRequest servletrequest, ServletResponse servletresponse)
    throws ServletException, IOException;
    public String getServletName()
    return config.getServletName();
    private transient ServletConfig config;
    4. finally ur init() without arugments method will exected.
    Edited by: Lakshman.Balanagu on 26 Aug, 2008 3:43 PM
    Edited by: Lakshman.Balanagu on 26 Aug, 2008 3:44 PM

  • How can servlet serve more than one client's socket links when tomcat start

    I have done this in the servlet's 'init' method:
    while (true)
    Socket sk = server.accept ();
    new ServerThread (sk).start ();
    but tomcat STOPPED at this point! The webapp didnot even been installed. But I want to show the index.jsp pages of the webapp, the code above only running at background. How can I do that?

    Eeeew... what are you doing there? Of course Tomcat stops. You have an infinite loop, and accept() blocks until someone actually connects.
    And a servlet shouldn't be using sockets anyway. This is most ugly, and possibly against the J2EE specs.

  • Can servlet talk to a GUI?

    Hi everybody,
    I am still new to java programming and I have a problem with a task and don't find any documentation on this specific subject. I have to write a program which is retrieving information from a database and displays this information in a browser. The user shall be able to modify this information or enter new information from the browser and store it back in the database . My idea is to use a servlet to do the logic in the program (like the jdbc part) and to use an applet with a GUI (e.g. AWT) to display the information retrieved from a DBMS by the servlet. By using a GUI with textfields, for example, it would be possible to modify the contents or enter new data.
    My question:
    Is it possible that a servlet can "talk" to a GUI in an applet running in a remote browser so that this GUI can display the information? I don't know how to transfer the information gathered by the servlet to the GUI in the applet.
    If you can help me or if you know where to find information about this topic please let me know!
    Thanks a lot.

    A servelt can communicate with an applet through Streams.
    First you need to open a http connection to the servlet (from the applet) and then you open the Object Streams:
    HttpURLConnection con = (HttpURLConnection)servlet.openConnection();
    ObjectOutputStream out = new ObjectOutputStream(con.getOutputStream());By the side of the servlet you can open the streams with the methods from the HttpServletRequest object: getInputStream() and getOutputStream().

  • How can servlet return data as download file from browser ? !!! URGENT !!!

    My servlet query data from database and would like to return the data as text file.
    How can I return data to the browser as user click a file to download ?
    How can I set the file name ? (default name is the servlet name that I don't want it to be)
    Which content type should I return to browser to prevent browser to display data immediately but save instead ?
    Thank you very much !

    I am having the same issue. Did you ever discover a way to change the "file name" in the browser. I've tried changing numerous HTTP header fields, to no avail.
    Marc

  • Can servlets be developed locally using IE without dialing out?

    beyond the user changing their settings is their something I can do?

    Yes, but you need a servlet runner such as tomcat, java web server, jwsdk etc,etc. You are always able to call your own loopback (localhost) or your own computer name (IP) locally, without needing to be connected to the internet. But you will need one of the servlet runners (servers) mentioned above. Go get forte, it comes with tomcat all configured for you.

  • How can servlet return the output as html content with drawing picture?

    Does anybody know how can a servlet return the output as html content with drawing picture?
    The drawing picture is drawn at runtime by the servlet.

    Thanks, BalusC.
    But I am not sure if I understand your reply fully.
    From my understanding, you are telling me to first generate a html from a servlet with the image <IMG> tag pointing to a servlet which will be responsible to generate an image?
    For example, <IMG SRC="http://myserver/servlet/testservlet">
    Could you confirm this?

  • Can I use Serialization if I have to update my class files?

    Hi,
    I'm writing a game right now, and I'm using Serialization to implement saving maps in it. Its saving me a whole bunch of time right now, but I'm worried that if I make even the slightest adjustment to my class files, then old saved maps won't work anywhere.
    Is there anyway to work around this?
    Thank you for any suggestions.
    -Cuppo

    Yes there is; the description of that all can be found in the API docs for the
    Serializable interface; in short: you have to write/read the members of
    your classes yourself by implementing two special methods; that's all.You don't even have to do that. As long as you provide a serialVersionUID
    member and obey the versioning constraints in the Serialization specification
    you don't have to do any extra programing.You're right; your scenario is even simpler; I discovered something funny though:
    my 1.4.2. API docs lack all documentation of the serialVersionUID final member in
    the description of the Serializable interface. It is present in the 1.5. docs, strange ...
    kind regards,
    Jos

  • Applet-Servlet communication (Serialization)

    I need to pass certain objects from server side to the client applet. My applet is embedded in the jsp. Just before calling the applet, Im able to pass the string parameters via jsp <param>tag. Now I need to pass an object which is of a class type. I resorted to serialization. When i try to serialize the object in jsp and try to deserialize it in the applet I get this exception "java.io.StreamCorruptedException: invalid stream header".The jdk versions of applet and servlet are the same. Classes are serializable. But yet am not able to find out the reason for this annoying exception. Please help!

    Thanks for your reply.
    Iam calling the writeObject on an object, writing it to ObjectOutputStream and Iam using ObjectInputStream at the applet side to readObject which is serialized! Iam making use of HttpURLConnection only. Let me cut & paste a part of my applet & JSP code here.
    APPLET:
    =======
    HttpURLConnection jspConnection = null;
              String urlString = ServerAdd+"/xyz/abc.jsp";
              try{
                   URL url = new URL(urlString);
                   jspConnection = (HttpURLConnection)url.openConnection();
              }catch(Exception e){
                   e.printStackTrace();
              jspConnection.setDoInput(true);
              jspConnection.setDoOutput(true);
              jspConnection.setUseCaches(false);
              jspConnection.setDefaultUseCaches(false);
              jspConnection.setUseCaches(false);
              jspConnection.setDefaultUseCaches(false);
              jspConnection.setRequestProperty("Content-Type", "application/octet-stream");
    try{
    System.out.println("Getting inputstream from servlet...");
                   ObjectInputStream inputFromServlet = new ObjectInputStream(jspConnection.getInputStream());
                   System.out.println("Getting bpiPackage from servlet...");
                   bpiPackage = (BPIPackage)inputFromServlet.readObject();
                   inputFromServlet.close();
                   jspConnection.getInputStream().close();
                   jspConnection.disconnect();
                   jspConnection = null;
                   System.out.println("Data transmission from servlet complete...");
              }catch(MalformedURLException e){
                   System.out.println(e);
              }catch(IOException e){
                   System.out.println(e);
              }catch(ClassNotFoundException e){
                   System.out.println(e);
    StreamCorruptedException is thrown here
    ObjectInputStream inputFromServlet = new ObjectInputStream(jspConnection.getInputStream());
    JSP side:
    ========
    BPIPackage pkg = (BPIPackage)session.getAttribute("pkg");
         try{
              System.out.println("Sending package object to applet...");
              ObjectOutputStream outputToApplet = new ObjectOutputStream(response.getOutputStream());
         System.out.println("Writing package object...");
         outputToApplet.writeObject(pkg);
         outputToApplet.flush();
         outputToApplet.close();
         System.out.println("Data transmission to applet complete...");
         }catch (IOException e){
              e.printStackTrace();
    This exception occurs only when applet tries to deserialize data passed from JSP. There is no problem in the connection because there is no exception thrown when the reverse happens (ie.serializing in the applet and deserializing in the JSP using the same jspConnection)
    I hope the code makes my problem clear to you.
    In your reply I did not get this:
    "writing it to a ByteArrrayOutputStream, and taking those bytes, and base64 encoding them, sticking the value in an applet param.
    Then the applet is getting the applet param, and building a ByteArrayInputStream from it, and calling readObject on it.Could you elaborate more?

  • Can servlets/ jsp automatically run perl scripts and executables?

    I'm a student and am new to to servlets and web programming in general.
    I need to know if it's possible to run perl scripts and executables automatically from servlets/ jsp.
    The program I am planning on creating should have a client outside a firewall that uploads perl files to a gateway machine inside the firewall, the servlet should be able to run this perl file, and then pass the resulting file as an argument to an executable, to be run by another servlet on a different server.
    I've tried looking everwhere for an answer to this and am about to revert to a cgi based approach because I'm not sure if it would work so any help/ suggestions would be much appreciated.

    Hallo,
    I think using java Runtime will help. you can do Processes that execute shell or system commands through
    Process process = Runtime.getRuntime().exec("your perl scripts here!");
    Bye

  • Can Servlet embed in Jsp files?

    Dear Friends,
    I am new to jsp
    Can embed HttpServlet in my jsp page ?
    my java program contains outputstream, printwriter etc.,
    please help me.
    Thanks a lot.
    Yours Iee

    hi
    to enable u to see your codes more clearly, i would suggest that u separate ur docs into JSP and servlet.
    this allows u to correct ur errors easily too.
    cos currently i am usin both JSP and servlet too.
    u just need to call ur servlet from ur JSP page..
    btw both JSP and servlet can be used for designin websites.. but usin JSP might be easier..
    wonder if the above helps..
    regards

  • Can weblogic run serializer classes created by wscompile tool

    Hi,
    I am trying to deploy a webservice on weblogic.
    This webservice implements a given wsdl.
    I have created type mapping classes from 'wscompile' tool and not by 'autotype'
    provided by weblogic as i want my code to follow JAX-RPC standards and it should
    not depend upon weblogic classes.
    when i package the webservice and deploy it on weblogic, i get the following error:
    weblogic.webservice.server.ConfigException: failed to add type mapping to registry:
    - with nested exception:
    [java.lang.InstantiationException: com.egain.adapter.StartMonitoringResponse_LiteralSerializer]
    at weblogic.webservice.server.WebServiceFactory.initTypeMaps(WebServiceFactory.java:228)
    How can we deploy a webservice created with JAX-RPC standard (with either Apache
    Axis or JWSDP) on weblogic?
    I am using WLS 7.0 SP1.
    Thanx for any help in advance.
    Davinder

    JAX-RPC serializer classes are not portable. So you can not use the
    serializer classes
    generated by Sun's RI in weblogic JAX-RPC runtime.
    provided by weblogic as i want my code to follow JAX-RPC standards and itshould
    not depend upon weblogic classes.You dont have to refer any weblogic specific classes to use WLS JAX-RPC
    impl. You
    only need to use the weblogic provied tools. The application code you write
    is portable.
    Check out the edoc for more details:
    http://edocs.bea.com
    -regards,
    manoj
    "davinder" <[email protected]> wrote in message
    news:3e66e03a$[email protected]..
    >
    Hi,
    I am trying to deploy a webservice on weblogic.
    This webservice implements a given wsdl.
    I have created type mapping classes from 'wscompile' tool and not by'autotype'
    provided by weblogic as i want my code to follow JAX-RPC standards and itshould
    not depend upon weblogic classes.
    when i package the webservice and deploy it on weblogic, i get thefollowing error:
    >
    weblogic.webservice.server.ConfigException: failed to add type mapping toregistry:
    - with nested exception:
    [java.lang.InstantiationException:com.egain.adapter.StartMonitoringResponse_LiteralSerializer]
    atweblogic.webservice.server.WebServiceFactory.initTypeMaps(WebServiceFactory.
    java:228)
    >
    How can we deploy a webservice created with JAX-RPC standard (with eitherApache
    Axis or JWSDP) on weblogic?
    I am using WLS 7.0 SP1.
    Thanx for any help in advance.
    Davinder

  • Servlet doing serialization

    Hi all,
    I'm designing a small app in order to perform compilation test on struts framework using flash tools. The project is organized this way: the user tells how many "compilation test" he wants to perform on the main page and then these informations are passed to a servlet which generates fake informations about the user and perform the compilation of a Flash animation. All these informations (first name, last name, mail, various informations and path to flash animation) are stored inside a separate class which also reads the content of the flash file and stores it into an attribute. This class implements the serializable interface. When things are done, I try to serialize the object.
    Problems are beginning at this point: I'm not able to serialize my object. In fact, I generate a random filename and pass it to a FileOutputStream, so it is supposed to create my file. Despite of this, I get an *annoying* Error 500 which tells me the following:
    java.io.FileNotFoundException: /var/lib/tomcat5/webapps/struts_test/WEB_INF/classes/objects/aGdsPhOboRJgf.ser (No such file or directory)
         java.io.FileOutputStream.open (Native Method)
         java.io.FileOutputStream.<init> (FileOutputStream.java:179)
         java.io.FileOutputStream.<init> (FileOutputStream.java:70)
         java.io.FileWriter.<init> (FileWriter.java:46)
         struts_test.IdentifyAction1.execute (IdentifyAction1.java:76)
         org.apache.struts.action.RequestProcessor.processActionPerform (RequestProcessor.java:421)
         org.apache.struts.action.RequestProcessor.process (RequestProcessor.java:226)
         org.apache.struts.action.ActionServlet.process (ActionServlet.java:1164)
         org.apache.struts.action.ActionServlet.doPost (ActionServlet.java:415)
         javax.servlet.http.HttpServlet.service (HttpServlet.java:709)
         javax.servlet.http.HttpServlet.service (HttpServlet.java:802)
         sun.reflect.NativeMethodAccessorImpl.invoke0 (Native Method)
         sun.reflect.NativeMethodAccessorImpl.invoke (NativeMethodAccessorImpl.java:39)
         sun.reflect.DelegatingMethodAccessorImpl.invoke (DelegatingMethodAccessorImpl.java:25)
         java.lang.reflect.Method.invoke (Method.java:597)
         org.apache.catalina.security.SecurityUtil$1.run (SecurityUtil.java:243)
         java.security.AccessController.doPrivileged (Native Method)
         javax.security.auth.Subject.doAsPrivileged (Subject.java:517)
         org.apache.catalina.security.SecurityUtil.execute (SecurityUtil.java:272)
         org.apache.catalina.security.SecurityUtil.doAsPrivilege (SecurityUtil.java:161)This stacktrace guides us to the idea that we don't have deployed the right security policy, but it isn't. My catalina.policy contains the following:
    grant codeBase "file:${catalina.home}/webapps/struts_test/-" {
         permission java.io.FilePermission "/var/lib/tomcat5/webapps/struts_test/WEB-INF/classes/struts_test/flash/-", "read,write";
         permission java.io.FilePermission "/var/lib/tomcat5/webapps/struts_test/WEB-INF/classes/objects/test.ser", "write,read";
    };So I've tried to tell it a nice permission java.security.AllPermission; and this results in the non-appearance of the error message, but the file is *NOT* created... It's going to drive me nuts... So if anyone has an idea, I'd be honoured to read it :)
    Thanks!
    System Configuration:
    OS: Ubuntu Linux 7.04
    Tomcat: version 5.0
    Java: JDK1.6.0_02
    SE with some Ant and Struts-related libraries and

    Are you sure the path is correct?
    ava.io.FileNotFoundException: /var/lib/tomcat5/webapps/struts_test/WEB_INF/classes/objects/aGdsPhOboRJgf.ser (No such file or directory)
    Should it not be "WEB-INF" instead of "WEB_INF"?

Maybe you are looking for

  • Will not install on windows 7 x64

    I get error on install on a Dell Windows 7 x64 bit laptop - trying to install the Cloud gives me the same error - There is a problem with this windows installer package A program required for this install to complete could not be run. Contact your su

  • Trouble with FP 10.3.183.7 upgrade - wasn't working and now doesn't download

    Current system info: Windows 7 (64 bit) Internet Explorer 9 (using 32 bit for downloading FP) I upgraded to 10.3.183.7 and immediately noticed my laptop unable to display/use Flash features (facebook games, online flyers, video, etc) I uninstalled an

  • SAP Report to find usage/transactions access per module

    Hi, Is there any report/tool avialable in SAP to see how many transactions are being executed in a given period of time per MODULE. Actually management wants to see the details and asked me to provide the summarized report...(i believe they want to s

  • Help:  encoder not recognizing audio in mpg

    i have to convery a number of mpgs into flvs using flash's video encoder. the mpgs have audio, however when i bring them into the encoder, click on settings, and then click on the audio tab, it's all grayed out like it's not recognizing it has audio.

  • Usefull ABAP Programm

    Hi Experts, Any Usefull ABAP program for SD, MM, FI, which one will come on daily needs. Thanks