Pass Object Between Applet and JSP Page

Hi all,
How can I pass an Object(such as Vector, File), rather than just string to the Applet from a JSP page?
Thank you.

I used Base64Encoder and Base64Decoder from servlets.com utilities.
* convert any serializable object to a String
public synchronized static String objectToString(Serializable obj) throws Exception {
    ByteArrayOutputStream bos = new ByteArrayOutputStream(100);
    ObjectOutputStream oos = new ObjectOutputStream(bos);
    oos.writeObject(obj);
    byte[]bytes = bos.toByteArray();
    bos = new ByteArrayOutputStream(); //to save the encoded String
    Base64Encoder enc = new Base64Encoder(bos);
    enc.write(bytes);
    String encodedString = bos.toString();
    //close all
    enc.close();   
    oos.close();
    bos.close();
    return encodedString;
* Recreates the object from the encoded String
public synchronized static Object stringToObject(String str) throws Exception {
    ByteArrayInputStream bis = new ByteArrayInputStream(str.getBytes());
    Base64Decoder dec = new Base64Decoder(bis);
    ObjectInputStream ois = new ObjectInputStream(dec);
    Object obj = (Object)ois.readObject();
    ois.close();
    dec.close();
    bis.close();
    return obj;
}

Similar Messages

  • Passing objects between Servlets and JSP

    Hi,
    I have passed a ResultSet from a Servlet to JSP using RequestDispatcher forward(). I can access the ResultSet in the JSP page. How can I now pass this ResultSet into another JSP page once the form has been submitted?
    Thanks in advance.

    You should never passing expensive resources like ResultSet around like that. This indicate an open DB connection somewhere while it should already be closed at this stage.
    Read on about the DAO pattern and make use of servlets and beans.

  • How to pass values between applet and jsp

    I have a jsp calling an applet which needs to return value to the calling jsp based on the action. Once the applet returns value to the calling jsp, I need to put that value into the session so that I can use it for the other pages. Could anyone have suggestion how to do it. I am new to applet development. Appreciate your help.

    Why does it have to send the value back via the same JSP? Why not create a servlet to take input from the applet?

  • Can objects be passed between Applets and JSP?

    Can objects be passed between Applets and JSP? If so how? Thanks in advance.
    Scott

    see if this helps,
    http://forum.java.sun.com/thread.jsp?forum=54&thread=136847

  • Applet and JSP Page

    Hi.
    I have a class called clsDbGrid under the ./classes/pkgDB and a JSP page under de ./web directory. I need to call the class from my JSP. I wrote the follow code:
       <applet class="clsDbGrid.class" width="640" height="480">
           The browse doesn't support JAVA
       </applet>But this code doesn't work. What's wrong? I put the entire path for package and doesn't work again.
    Please, I'm beginner in Java and need a help.
    Thanks.
    Marco.
    P.S - Sorry for my terrible english. I'm from Brazil.

    See if this helps:
    http://java.sun.com/docs/books/tutorial/deployment/applet/html.html

  • Juggle between jstl and jsp!

    I have a list of items and whose size is obtained by jstl as follows:
    <c:set var="num" value="${fn:length(form.namesList)}"/>I have to find the number of blocks using jsp and I am trying as follows which is giving jspException.
    <%int numCols = (int)Math.ceil( num / 10.0);%>Can anyone tell me the problem over here?
    I need to use numCols to display my results using jstl as follows:
    <c:forEach var="y" begin="${1}" end="${numCols }">
    </c:forEach>Can juggle between jstl and jsp like this?

    This depends on the version of JSP you are using:
    If you are using JSP 2.0 (like Tomcat 5), make sure you have downloaded and installed JSTL 1.1 and set the web.xml up to use the Servlet 2.4 specs. Then the code you wrote should work.
    If you are using JSP 1.x (like Tomcat 4 and below), make sure you have JSTL 1.0. Then you can only use EL (the Expression Language used to translate ${...} expressions) inside JSTL.
    If you want to use EL inside your custome tags, look through the Apache Jakarta sight. Somewhere they have an ELExpression translator (a couple of classes actually - whose full names I forget). These classes will let you take the ${...} expressions in as strings, pass them through the translators and get the correct objects back out.
    Or you could go a simpler root:
    <mob:whatever object="test" name="newname" />
    then in your custom tag:
      MyType test = (MyType)pageContext.findAttribute(object);
      test.setName(name);

  • (UIX XML) Sharing Connection objects between BC4J and custom java.

    If I have a UIX XML page that contains some BC4J application modules, then in the event handler I call [public static EventResult handleMyEventEvent (BajaContext context, Page page, PageEvent event..) ], which in turn calls some java classes I have written that take a java.sql.Connection object and access the database doing some updates/inserts with this Connection object (via JDBC)....HOW CAN I USE THE SAME TRANSACTION AS WAS USED IN THE BC4J APPLICATION MODULE...i.e. CAN I SHARE THE CONNECTION OBJECT BETWEEN BC4J AND MY OWN JAVA CLASSES THAT USE JDBC?
    What are the best ways to share such a transaction?
    Thanks,
    Paul.

    Would it be easier to use a custom method on the bc4j Application module?
    Take this scenario...
    1. User opens UIX XML web page which opens a bc4j App Module..it has a VO based on all employees.
    2. User presses the add button and a new employee is created (using the bc4j App Module).
    (Notice: no commit yet!)
    3. User presses the submit button...fires event REVIEW_SALARY.
    4. This event is 'handled' in the event section of the UML XML...it calls:-
    public static EventResult handleREVIEW_SALARYEvent (BajaContext context, Page page, PageEvent event)...
    5. I now want to call a java class I wrote that computes an employees new salary and updates the employee record with this new salary. This update will fail unless it is part of the same transaction as the one used by the bc4j App Module (that inserted the new employee).
    How best to proceed from here?
    How about having a method on the bc4j App Mod's VO called 'reviewSalary'? Calling this would use the same transaction? I could then call my java class from within the VO's method? However do I still have the same problem in that my java class expects to be passed the connection object?
    The approach you suggested previously seems a touch dangerous....in that these are not 'publically exposed'...and a new release of JDev may break my code.
    Thanks,
    Paul.

  • Switching between Design and JSP tabs add code?

    I am new to SJSC and I am taking the time to go through all of the little odds & ends of the IDE.
    I was looking at:
    http://blogs.sun.com/roller/page/tor?entry=computing_html_on_the_fly
    And I decided to try this.
    When I add the following in the JSP tab:
    <h:outputText binding="#{Page1.tableHtml}" id="outputText1"/>Save.
    Then click on the Design tab, then go back to the JSP tab, I now have:
    <h:outputText binding="#{Page1.tableHtml}" id="outputText1"/>
    <h:outputText binding="#{Page1.outputText1}" id="outputText1"/>It's late here, but this doesn't make any sense, why would switching between Design and JSP tabs add code?
    Thanks,
    --Todd                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

    Girish: I followed these steps:
    1.) Downloaded:
    Sun Java Studio Creator 2, Multilanguage creator-2-windows-ml.exe 254.23 MB
    2.) When I started the install, I received the message:
    Welcome to Sun Java(TM) Studio Creator 2! You are installing: Sun Java Studio Creator 2 development environment Sun Java System Application Server Platform Edition 8.1 2005Q1 Update Release 2 Bundled database
    3.) Installed version:
    Product Version: Java Studio Creator 2 (Build 060120)
    IDE Versioning: IDE/1 spec=5.9.1.1 impl=060120
    Also, Under, the Palette window: Standard component list, there is a component labeled Output Text.
    When placed on a jsp, the following code is produced:
    <h:outputText binding="#{Page1.outputText1}" id="outputText1" style="position: absolute; left: 24px; top: 48px"/>Thanks,
    --Todd                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

  • SAP connector and Jsp page

    hi Experts,
    Can anyone please send me a working example project for SAP connector and Jsp page at [email protected]
    Regards,
    Sanjyoti.

    Hi, 
    Use this example
    import com.sapportals.connector.ConnectorException;
    import com.sapportals.connector.connection.IConnection;
    import com.sapportals.connector.execution.objects.INativeQuery;
    import com.sapportals.connector.execution.objects.InvalidQueryStringException;
    import com.sapportals.connector.execution.objects.QueryExecutionException;
    import com.sapportals.connector.metadata.CapabilityNotSupportedException;
    import com.sapportals.portal.ivs.cg.ConnectionProperties;
    import com.sapportals.portal.ivs.cg.IConnectorGatewayService;
    import com.sapportals.portal.ivs.cg.IConnectorService;
    import com.sapportals.portal.prt.component.*;
    import com.sapportals.portal.prt.resource.ResourceException;
    import com.sapportals.portal.prt.runtime.PortalRuntime;
    public class TestJDBC extends AbstractPortalComponent
    public void doContent(IPortalComponentRequest request, IPortalComponentResponse response)
    throws ResourceException
    // Open a connection
    IConnectorGatewayService cgService = (IConnectorGatewayService)
    PortalRuntime.getRuntimeResources().getService(IConnectorService.KEY);
    ConnectionProperties prop = new ConnectionProperties(request.getLocale(),
    request.getUser());
    IConnection client = null;
    try {
    client = cgService.getConnection("System1", prop);
    } catch (Exception e) {
    response.write(e.toString());
    return;
    try {
    // Issue SQL Query statement
    INativeQuery query = client.newNativeQuery();
    String queryStr = "SELECT [CategoryID], [CategoryName], [Description] FROM
    [Categories]";
    //IQuery query = client.newQuery();
    //query.execute(queryStr);
    Object result = query.execute(queryStr);
    //ResultSet singleResult = ((ResultSet) result).getRow();
    //IRecordSet result = query.retrieveRecordSet();
    // Iterate returned result
    ResultSetMetaData recordMetaData = ((ResultSet)result).getMetaData();
    int colNum = recordMetaData.getColumnCount();
    //result.beforeFirst();
    while (((ResultSet)result).next()) {
    for (int i = 1; i <= colNum; i++) {
    response.write(((ResultSet)result).getString(i) + "<br>");
    // Close the connection
    client.close();
    } catch (QueryExecutionException e) {
    response.write(e.toString());
    } catch (CapabilityNotSupportedException e) {
    response.write(e.toString());
    } catch (ConnectorException e) {
    response.write(e.toString());
    } catch (InvalidQueryStringException e) {
    response.write(e.toString());
    } catch (ResourceException e) {
    response.write(e.toString());
    } catch (SQLException e){
    response.write(e.toString());
    }catch(Exception e){
    response.write(e.toString());

  • Use context to pass value between JPF and Java Control

    hi,
    Can we use context to pass value between JPF and Java Control? It works if i m using InitialContext in the same machine but i dun think it will works if i put Web server and application server in different machine. Anyone have an idea how to do it?
    I also want to get the method name in the onAcquire callback method. Anyone knows how to do this?
    thks
    ?:|

    Hi.
    Yoy can the next options for make this:
    1. Pass your values in http request.
    example: http://localhost/index.jsp?var1=value1&var2=value2&var3....
    2. You can use a no visible frame (of height or width 0) and keep your variables and values there using Javascript, but of this form, single you will be able to check the values in the part client, not in the server. Of this form, the values of vars are not visible from the user in the navigation bar.
    Greeting.

  • Propagation of ctx between EJB and JSP

    Hello,
    Does anybody know how to propagate the Security
    Context between EJB and JSP so that when I login in my JSP page the user will be after recognized in my EJB system ?
    Thanks
    Francesco

    try this...as a test..
    take a simple Contact ejb (as simple as you can make it, just a name and email address). In the ejb-jar.xml set up a role, for example, user, and restrict the access to only this role for all methods.
    try to access the ejb from a jsp, and you should get the login form identified in your web.xml file.
    make sure that the ejb is noted in the web.xml file, also.
    this should work...
    no try this...identify a role in your web.xml file, (user, for example) and restrict the access to the a particular jsp which is not calling the ejb. IF you navigate to this jsp, you should get the login prompt...
    this should work....
    now the tough part
    in your application.xml create a role with the same name, user. By doing this, you have created a global role, and connect the two together.
    Now point your browser to the restricted jsp with no calls to the ejb...you should get the login, so login in.
    now navigate to your jsp which is unrestricted, but calls the restricted ejb...
    there should now be no login prompt.
    This should work.

  • Difference between facelets and jsp xml in Document Type

    I want difference between facelets and jsp in Document Type in JDeveloper 11gR2 (11.1.2)
    Thanks
    Edited by: Amr Ahmed on Jun 8, 2011 7:46 AM

    Let's see.
    Facelets creates a facelets page
    JSP creates a JSP page
    {noformat}:){noformat}
    Facelets is the "official" view language for JSF 2.0
    http://www.realdevelopers.com/blog/development/facelets-vs-jsp should give you some more insight as well.
    John

  • Difference Between Applet and Swing

    Difference Between Applet and Swing

    The advantages and disadvantages of both applets and Swing are the small fluffy elephants you get inside of every box. They're quite well trained and can skeletonize your neighbors' annoying pets upon command.

  • Diff  between logical and physical page ?

    hi
    what exactly difference between logical and physical pages?
    where to set page size in report designer?
    after seting paper size in report designer can i readjust in print dialogue box?
    which is will be effected?
    please explain

    A logical page can contain several physical pages. Assume you want to create a format which is larger then your printer is able to print, then you can define a logical size, which contains n pages horizontally and m pages vertically.
    To set the page size for your report have a look at the properties in the main section of your paper layout.
    Regards
    Rainer

  • What are the differences between Applet and Swings

    Please let me know the differences between Applet and Swings.

    Quit cross-posting.
    http://forum.java.sun.com/thread.jspa?threadID=755100
    http://forum.java.sun.com/thread.jspa?threadID=755099
    http://forum.java.sun.com/thread.jspa?threadID=755006

Maybe you are looking for

  • 403 Error running ADF application in JCS

    I am getting a 403 error while running a ADF application in JCS. I defined a security role and mapped it to a custom role. web.xml and weblogic.xml are pasted below <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"          xsi:schemaLoc

  • Advantage of using RAW devices for storing database

    Hi, Marry Christmas to all. Oracle 10g version 10.2.0.1.0 (rac) OS : HP-UX 11i I am new to this enviornment. We are using raw devices for storig the database. Please tell what are the advantages for using raw devices for storing the database? Thanks.

  • Am having thousands of unsolicited emails coming into my computer

    I am receiving "Return to sender" emails (over 1,000 each day). I have not sent any of these emails, and they have attachments that they want me to open, but have not opened any of them. How can I stop this from happening? This began over the weekend

  • Patching strategy for Production environment

    Hi all, Can anyone share their patch strategy specially for production environment?? We have production environment and we are planning to patch our databases using PSU pacthes with no downtime. Our production environment has standby. We have one opt

  • Can't submit app update at last step

    Trying to submit an app update to one of our existing apps. Build is uploaded, all is fine... until I get to the last page where it asks about third party content and IDFA rights. I check everything appropriately, but the "Submit" button stays greyed