Passing data from Applet to JSP and back

What is the best way for me to communicate between an Applet and a jsp page? I want to be able to call Applet methods from the JSP and be able to send data to the JSP from the Applet. Thanks.

Can't do this
JSP lives on the server. When it's done, the code is sent to the client
So, in terms of lifespan...
JSP -> Internet -> Client -> Applet
JSP is dead before applet starts

Similar Messages

  • Pass data from servlet to jsp using sendRedirect

    Hi,
    I am passing data from servlet to jsp using forward method of request dispatcher but as it doesn't change the url it is creating problems. When ever user refreshes the screen(browser refresh) it's re-loading both servlet and jsp, which i don't want to happen. I want only the jsp to be reloaded.
    Can I pass data from servlet to jsp using sendRedirect in this case. I also want to pass some values from servlet to jsp but without using query string. I want to set some attributes and send to jsp just like we do for forward method of request dispatcher.
    Is there any way i can send data using attributes(without using query string) using sendRedirect? Please let me know

    sendRedirect is meant as a true redirect. meaning
    you can use it to redirect to urls not in your
    context....with forward you couldn't pass information
    to jsps/servlets outside your own context.Actually, you can:
    getServletContext().getContext("/other").getRequestDispatcher("/path/to/servlet").forward(request, response)I think the issue here is that the OP would like to have RequestDispatcher.forward() also update the address in the client's browser. That's not possible, AFAIK. By the time the request is forwarded, the browser has already determined the URL of the servlet, and the only I know of way to have the browser change the URL to the forwarded Servlet/JSP is to send a Location: header (i.e. sendRedirect()). Remember that server-side dispatching is transparent to the client. Maybe there's some tricky stuff you can do with JavaScript to change the address in the address bar without reloading the page?
    Brian

  • Passing data from EJBs to JSPs

    Hi all, I'm trying to enhance an exercise I've been working on. I have a couple of beans "ProductBean" and "ProductBasket". I want to add items to the basket and then display them to the screen. I am getting an error when trying to use the Vector object in the JSP. I'm not sure how you go about passing data around from a bean to a JSP, should I be using a servlet to dispatch data from a bean to a JSP?
    Once clicking the submit button on my HTML form and the item has been added to the basket how would you recommend I read the basket contents back out to the screen using my existing code below?
    Cheers in advance for any help.
    <html>
    <body>
    <jsp:useBean id="shop1" class="shop.ProductBean" />
    <jsp:setProperty name="shop1" property="*" />
    You clicked: <%= shop1.getTitle()  %>
    <br /> <%= shop1.getPrice() %>
    <jsp:useBean id="basket1" class="shop.ProductBasket" />
    <%
         for(int i=0; i<v.size(); i++){
             System.out.println(v.elementAt(i).getTitle()+"<br />");
    %>
    </body>
    </html>
    package shop;
    import java.util.Vector;
    public class ProductBasket{
         Vector v = new Vector();
         public void addToBasket(ProductBean bean){
              v.addElement(bean);
    package shop;
    public class ProductBean{
         private String title = new String();
         private float price = 0.0f;
         private String description = new String();
         private String artist = new String();
         private String type = new String();
         public String getTitle(){
              return this.title;
         public void setTitle(String title){
              this.title = title;
         public float getPrice(){
              return price;
         public void setPrice(float price){
              this.price = price;
         public String getDescription(){
              return this.description;
         public void setDescription(String description){
              this.description = description;
         public String getArtist(){
              return artist;
         public void setArtist(String artist){
              this.artist = artist;
         public String getType(){
              return type;
         public void setType(String type){
              this.type = type;
              <form action="basket.jsp" method="post">
                   <input type="hidden" name="title" value="Java Demo" />
                   <input type="hidden" name="price" value="12.99" />
                   <input type="hidden" name="description" value="Sun MS CD - excellent!!!  MUST BUY" />
                   <input type="hidden" name="artist" value="Sun MS" />
                   <input type="hidden" name="type" value="cd" />
                   <input type="submit" value="Submit" />
              </form>

    1) There are no EJB's in this code. JavaBeans are not EJB's!
    2) You never import the Vector class into your jsp, nor do you declare the variable 'v' in it. Thus, the errors.
    3) Vectors are legacy components and should no longer be used. Use List implementations instead. Or better yet, abstract your collections entirely from your JSP by using JSTL.
    4) If you're going to use Beans in your JSP, don't use scriptlets to access their properties, use the bean access methods. Read the JSP tutorial for examples.

  • Pass data from servlet to EJB3 and backward

    Hello All,
    The distributed application is being developed by the following scheme:
    J2EE Application Server (JBoss) - Servlet container (JBoss's contained Tomcat) - RIA client (Flex)
    Application server needs to handle client's requests and provide backward connectivity also.
    Servlets in this scheme are required by the BlazeDS library which is implemented as set of servlets handling HTTP requests from the clients.
    This forces us to:
    - invoke EJB from the servlet while handling client's requests.
    - invoke servlet from EJB for the sake of providing the client with urgent messages which need to be displayed immediately.
    The easiest ways to achieve that I am aware of are:
    - servlet invokes EJB via JNDI lookup (inefficient?)
    - EJB invokes servlet by passing HTTP request to web server (inefficient!)
    Is there standard and efficient ways to wire servlets(JSP) and EJB in either directions?
    Thanks,
    Alex.

    Hi Chicon,
    Thanks for advice. Probably I need to add few more words to make the question clearer.
    Chicon wrote:
    It is not the role of an EJB to fire a servlet. EJB's are only modules.
    In your case, the EJB invoked should pass the necessary data to the servlet. From the data it receives, the servlet has either to build and to send the HTML document(or other formats : pdf, txt, xml,...) or to fire the appropriate JSP to the client. The servlet may also call a more specific servlet to do the job, e.g. in a Struts like framework.- Invocation of EJB from servlet is one data flow direction. After EJB is invoked and finished, servlet gets results, makes its own job and sends data to clients either in html or binary AMF (Flex proprietary) format.
    - Invokation of servlet from EJB is another data flow direction. It will be employed, when server decides to inform all interested clients about an urgent event. Client are not asking for that event explicitly, but they are ready for handling such messages from the server.
    Of course, in order to achieve this, there is a need in a channel between server and each client. This is what BlazeDS for.
    The first requirement could be satisfied by either JNDI lookup or (as malrawi proposed) by dependency injection.
    The second one is a little bit harder... It may involve any other mediators, not necessarily the same servlets.
    I am looking for the best suitable solution now.
    Thanks,
    Alex.

  • Help needed: clarifying the use of beans to pass data from database to JSP

    Hi everyone,
    I am sure you all get fed up with being asked this question as I can see it is asked a lot when googled, but the answers given have not cleared things up for me.
    Anyway, I have a JSP page that contains a text box, submit button and a select box of size 10. The user enters a search string and the form submits the data and reloads the same page. From the code you can see the Name property of the bean is set.
    <jsp:useBean id="vtm" class="FinalYearProject.Types.VtmType" scope="page" />
    <jsp:setProperty name="vtm" property="NM" value="${param.NM}" />I then need to be able to use that name to query a postgresql database. I have a JDBCConnector class with the method:
        public ResultSet searchTable(String NM ) throws SQLException {
            String[] names = NM.split(" ");
            NM = "";
            for(int i = 0; i < names.length; i++) {
                NM = names[i] + "%";
            return stat.executeQuery("SELECT * FROM vtm WHERE nm ILIKE '" + NM + "';");
        }This method however can be changed.
    My question really is what is the best way for me to take the name, get the resultset and pass back the VtmType objects to the jsp so that I can populate my select box, and where should each part be handled i.e. the JSP page, the VtmType, the JDBCConnector.
    I may be going about it completely the wrong way and using beans incorrectly, but I just cant seem to get my head around the problem.
    Any help would be much appreciated,
    Thanks.

    Hi,
    Thanks for the help, I actually found some literature about the JSP Model 2 and realised that was what I needed to do. I have now re-written everything and it has made my life a lot eaiser, typically this was before I checked back on this post though!
    Anyway, I now have JSP pages requesting Servlets which create beans and call classes that access the database. The servlet then forwards the beans and where necessary a small of html to another JSP. Like you have suggested.
    One problem I have now however, is that the user needs to be logged in to access some of the pages. An error page with the correct message is displayed to the user when it is processed via the servlet.
    //Servlet detects an error
    request.setAttribute("errorMsg", "1");
    gotoPage("/loginError.jsp", request, response);
    //JSP detects which errorMsg to display
    <c:set var="errorMsg" value="${requestScope.errorMsg}" />However, when the user does not sign in and clicks a link which is blocked the JSP forwards directly to the error JSP.
    //Tests to see if user is logged in
    <c:if test="${empty user.username}">
        <jsp:forward page="/loginError.jsp">
            <jsp:param name="errorMsg" value="3" />
        </jsp:forward>
    </c:if>The problem with this is that the only way I can see of checking the errorMsg type is with:
    //JSP checks which errorMsg to display
    <c:set var="errorMsg" value="${param.errorMsg}" />Which is different to how I determine the errorMsg from the Servlet. Is there a way of getting the errorMsg type that is the same for both actions?
    Thanks.

  • Sending data from applet to jsp

    hi all....
    i m very new in java so please and please spend ur few movement for this topic.
    i want to run a jsp page from within an applet and evantually want to send data to jsp.
    the data is an array of string object or may be a properties object,
    say String[] strarry={stringdata},or Properties props={setofkeysandvalues}
    the url of the jsp is http://8084/UASProject/Registrationform.jsp
    i have copied a code snippet from a topic posted in this forum.
    now please where should i formate in the code below to achieve this?
        try{
            URL appletURL = getCodeBase();
            String strHost = appletURL.getHost();
            String strPort = String.valueOf(appletURL.getPort());
            String strProtocol = appletURL.getProtocol();
            int portNumber = Integer.parseInt(strPort);
            String strwp ="/UASProject/Registrationform.jsp";
            //TCP port;
            URL jspURL = new URL(strProtocol,strHost,portNumber,strwp);
            URLConnection jspCon = jspURL.openConnection();
            jspCon.setUseCaches(false);
            jspCon.setDoOutput(true);
            jspCon.setDoInput(true);
            //jspCon.set
            ByteArrayOutputStream byteStream = new ByteArrayOutputStream(512);
            PrintWriter out = new PrintWriter(byteStream,true);
           // String postData= "?xmlText=" + URLEncoder.encode(genXml(),"UTF-8");
            //out.print(postData);
            out.flush();
            String strLength = String.valueOf(byteStream);
            jspCon.setRequestProperty("Content-Length",strLength);
            jspCon.setRequestProperty("Content-Type","application/x-www-form-urlencoded");
            byteStream.writeTo(jspCon.getOutputStream());
            URL tempURL = new URL(String.valueOf(jspURL));
            getAppletContext().showDocument(tempURL);
        }catch(Exception e)   {}please explain the line String postData= "?xmlText=" URLEncoder.encode(genXml(),"UTF-8");+ why it is written for??

    angilna_loves_java wrote:
    hi all....
    i m very new in java so please and please spend ur few movement for this topic.Huh?
    i want to run a jsp page from within an applet and evantually want to send data to jsp.Oh good lord, why?!
    the data is an array of string object or may be a properties object,
    say String[] strarry={stringdata},or Properties props={setofkeysandvalues}
    the url of the jsp is http://8084/UASProject/Registrationform.jsp
    i have copied a code snippet from a topic posted in this forum.
    now please where should i formate in the code below to achieve this?I recommend you get a better grasp on Java and JSP before you go any further. I'm not clear on what problem you're having or what error your getting either.
    >
    try{
    URL appletURL = getCodeBase();
    String strHost = appletURL.getHost();
    String strPort = String.valueOf(appletURL.getPort());
    String strProtocol = appletURL.getProtocol();
    int portNumber = Integer.parseInt(strPort);
    String strwp ="/UASProject/Registrationform.jsp";
    //TCP port;
    URL jspURL = new URL(strProtocol,strHost,portNumber,strwp);
    URLConnection jspCon = jspURL.openConnection();
    jspCon.setUseCaches(false);
    jspCon.setDoOutput(true);
    jspCon.setDoInput(true);
    //jspCon.set
    ByteArrayOutputStream byteStream = new ByteArrayOutputStream(512);
    PrintWriter out = new PrintWriter(byteStream,true);
    // String postData= "?xmlText=" + URLEncoder.encode(genXml(),"UTF-8");
    //out.print(postData);
    out.flush();
    String strLength = String.valueOf(byteStream);
    jspCon.setRequestProperty("Content-Length",strLength);
    jspCon.setRequestProperty("Content-Type","application/x-www-form-urlencoded");
    byteStream.writeTo(jspCon.getOutputStream());
    URL tempURL = new URL(String.valueOf(jspURL));
    getAppletContext().showDocument(tempURL);
    }catch(Exception e)   {}please explain the line String postData= "?xmlText=" URLEncoder.encode(genXml(),"UTF-8");+ why it is written for??Please read the API docs if you don't know what a particular method in Java does.

  • Why passing string from applet to jsp doesn't work?

    Hi,all:
    I have a application requires applet to get client side info, then pass this "info"--string to the JSP.
    Applet code:
    try{
         URL url = new URL(getCodeBase(),"test.jsp?
    java.version=1.2.2&java.vendor=Sun);
         URLConnection conn = url.openConnection();
         conn.setDoOutput(true);
         conn.setUseCaches(false);
         conn.setRequestProperty("Content-Type", "application/octet-stream");
         conn.connect();
    } catch (Exception e) {
         System.out.println("The error is at URL:"+e.getMessage());
    My jsp code is:
    <%
    String java_version=request.getParameter("java.version");
    String java_vendor=request.getParameter("java.vendor");
    %>
    However, it doesn't work. Could anybody help me figure out?
    Thanks in advance.
    Paul

    Request Jsp with
    test.jsp?URLEncoder.encode("java.version")=URLEncoder.encode("java.version.value")&URLEncoder.encode("java.vendor")=
    URLEncoder.encode("java.vendor.value")

  • Problem in passing data from one .jsp page to another .jsp page

    i have a problem here
    Actually i have 2 jsp pages. What im trying to do here is actually i want to pass data from the first jsp page to the second for updating
    The first jsp page contains data that user wants to update in the form of table.
    <td><img src = "edit.gif" alt = "edit" border="0" ><td>
    <TD><%= Name %></td>
    <TD><%= rs.getInt("Age") %></td>
    <TD><%= rs.getString("Gender") %></td>
    So this page displays the data that users wants to update plus one image button (edit button). So when user clicks this button, all the data in this page will be brought to the second .jsp page called updatePersonal for updating.
    The problem here is that it is not displaying the existing data in the second .jsp page.
    The second page basically contains forms
    <INPUT TYPE="text" NAME="FirstName" maxlength="30" value = "<%=FirstName%>">
    Can someone please help me. I really dont know what to do..How do i get the data displayed in the text field that is passed from the first .jsp page..thankx in advance

    Please modify below code to:
    td><img src = "edit.gif" alt = "edit" border="0" ><td>
    -----------------modified code
    td><a href="updatePersonal.jsp?FirstName=<%=rs.getString(FirstName")%">&LastName=<%=rs.getString("LastName")%>&Age=<%=rs.getInt("Age")%>&Gender=<%=rs.getString("Gender")%>"><img src = "edit.gif" alt = "edit" border="0" ></a><td>
    I'm sure it works</a>

  • Passing data from webdynpro to BSP

    Hi Experts,
    Can anyone tell me is there any possibility of passing data from webdynpro to BSP and vice-versa.
    If so, kindly let me know.
    thanks a lot.
    regards
    vijay

    Two possible options, not sure however how this will work in practice.
    1. use the URL and pass additional parameters (http://help.sap.com/saphelp_nw70/helpdata/EN/7b/fb57412df8091de10000000a155106/content.htm)
    2. If in portal, do via portal eventing (http://help.sap.com/saphelp_nw70/helpdata/EN/f6/7d6f4151dc5758e10000000a1550b0/content.htm)

  • Passing data from JSP to existing iView in Portal

    Hello Experts,
    I'm new to EP and Web DynPro. Please provide your guidance for the following scenario:
    There are 2 iViews in different pages.
    iView 1(Web DynPro Java application) - its running in portal
    - created by other person long time back - it takes input from user to create a support message
    iView 2(JSP page)
    - since iView 1 is very generic, I have to create one more iView, which is simple & specific to user request, but should pass the data to the iView 1, which in turn will create a support message.
    My Question:
    Is it possible to pass data from my JSP page(in iView2) to the running application in iView1?
    (I don't have access to the code of the running application- so i can't use Client Data Bag or sessions)
    If the above condition is possible, then is it possible to hide the iView 1, so that user doesn't need to see the iView 1 when they submit data?
    Please guide me with sample code or links.
    Thanks in advance,
    Aruna Thamilmani

    You could have the Applet make a request to the server (via URLConnection).

  • Passing data from JavaScript to Applets (Error when trying to pass data)

    Hi,
    I've wrote a small applet for lists but when I try to pass data from my
    JavaScript to my applet, I get an "Error: Object doesn't support this property or method". I get this error with a select other sites including the page I'm writing, leading me to believe I may not have installed requried files or set required options. I've included the listing of the code snippet where the error occurs.
    document.listApplet.testMethod()OR when I use:
    document.applet(listApplet).testMethod()The applet is loaded by this statement:
    <OBJECT CODE="CustomAppletList" NAME="listApplet" ID="listApplet" WIDTH="1000" HEIGHT="600"></OBJECT>and loads fine but no data is passed through it's public methods. Can anyone suggest ideas how I can successfully pass data from my JavaScripts to my applets?
    Devyn

    this should work for you. In your javascript do this.
    var myApplet=document.listApplet;
    myApplet.testMethod()
    If you need more help let me know.
    Paul

  • Passing data from Javascripts to Applets

    Hi,
    I've wrote a small applet for lists but when I try to pass data from my
    JavaScript to my applet, I get an "Error: Object doesn't support this property or method". I get this error with a select other sites including the page I'm writing, leading me to believe I may not have installed requried files or set required options, though I've checked my settings . I've included the listing of the code snippet where the error occurs.
    document.listApplet.testMethod()OR when I use:
    document.applet(listApplet).testMethod()The applet is loaded by this statement:
    <OBJECT CODE="CustomAppletList" NAME="listApplet" ID="listApplet" WIDTH="1000" HEIGHT="600"></OBJECT>and loads fine but the error persists when attempting to call public method in my applet. Can anyone suggest ideas how I can successfully pass data from my JavaScripts to my applets?
    Devyn

    Hi,
    Thnx for the reply. I've tried as you suggested and modified my <OBJECT> line to:
    <OBJECT CODE="CustomAppletList.class" NAME="listApplet" ID="listApplet" WIDTH="1000" HEIGHT="600">
    <PARAM NAME="scriptable" VALUE="true"></PARAM>
    </OBJECT>But the error persists. I'm using IE6. I did not have such errors with IE5.
    I use the following code to test the applet tag I assigned at each step:
                        if (document.listApplet) {
                             document.write ("Applet Object (document.listApplet) exists.")
                        } else {
                             return
                        if (document.listApplet.object) {
                             document.write ("Applet Object (document.listApplet.object) exists.")
                        } else {
                             return
                        if (document.listApplet.object.testMethod) {
                             document.write ("Method textMethod() in applet has been validated and exists!")
                        } else {
                             document.write ("[2]")
                             return
                   document.write ("[11]")The debugging info from this code at the end of the html document I'm writing is:
    [1]Applet Object (document.viewer) exists.Applet Object (document.viewer.object) exists.[2][11]
    Devyn

  • How can I pass data from a form guide to another form in a business process

    How do we pass data from a form guide to another form(not necessarily a guide) without having to open the form. For example we have a small form guide to capture the contract id so we can then get data from contracts table to present to the user in a form. We want the user to open the guide (either Flex guide or form guide) to enter the contract id. Upon submission we want the process to get the contract data and put it into the form that will be opened at the next step by the user without having a user interact with the form to get the data into it. In other words we need the process to get the data and populate a different form than the form guide the contract id was entered in and this new form needs to be opened in the next step by the user.

    Firstly, I'm assuming that you have a Forms ES Server if you are rendering a Guide.  This could be either version ES1, ES2/2.5 or ES3/ADEP
    If you submit the form back to the server, you can populate a second (PDF/XDP) form with the data bound to the same schema/Data Model using Forms ES. 
    You referred to the next user in the chain - If you are using Process Management, this is very easy, as you define what form is used to render the data in the "Presentation & Data" section of the Assign Task activity

  • Passing data from one frame to another frame

    hello all, i am having a problem with passing data from one frame from another. I have a main frame when you click on connect button it display the second frame(class) that has 2 text fields and 2 buttons. When i click on connect it check if the data is correct. If the data is correct i want that frame to close and pass the data back to main frame. How can i do that.
    thank you

    hello all, i am having a problem with passing data
    from one frame from another. I have a main frame when
    you click on connect button it display the second
    frame(class) that has 2 text fields and 2 buttons.
    When i click on connect it check if the data is
    correct. If the data is correct i want that frame to
    close and pass the data back to main frame. How can
    i do that.
    thank you
    the original problem sounded like an ideal opportunity to use Modal Dialog. if you want one frame to display another to get user input then you need to stop the method in the main frame from executing until you recieve a valid input.
    you can use your own class and keep all of the components that you have in the connect frame but you would have to extend JDialog instead of JFrame.
    there is a way around it!
    if you must use JFrame for both, then you need to have access to the main frame in the connect frame, maybe pass the pointer to the constructor??
    anyway, when the connect frame is done with its duties, you have to use the pointer to call another method in the main frame that will continue the process. otherwise main frame doesn't know when connect frame is done and by that time, the method in main frame that instantiated the connect frame has long since died.
    also, it allows things to happen in the other window that you may not want to happen until the connect frame is done
    typically users of software start clicking around on things and you could have three or four connect frames going at the same time
    it's really best to use a Modal Dialog, it really can look just like a JFrame!!!!!!!!!!!!!!

  • Passing data from a container to another

    Hi,
    Let's say I have two containers (Container1=application , Container2).  Container1 gets some data from user, perform some database lookup and displays Container2 with the results from database lookup.
    Container1 --(call and display)--> Container2
    Below shows  how I am using a bindable variable in Container1 to pass the data from Container1 to Container2.  Also shows how I display Container2 from Container1.
    <!-- Container1 -->
    <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml">
       [Bindable] public var foo:String = "bar";
       private function loginHandler(event:LoginEvent):void
          mycontainer2 = new Container2();
          mycontainer2.name = "mycontainer2";
          this.addChild(mycontainer2);
    </mx:Application>
    I am accessing the data in Container2 as follow:
    <!-- Container2 -->
    {mx.core.Application.application.foo}
    Q1) Is there a better way to pass data from one container to another and access the data?
    Q2) Is this the only way to call and display Container2 from Container1?
    Q3) How can I move back to Container1 from Container2, i.e. Container2 call and display Container1
           Container2 --(back to)--> Container1

    Best practices call for using custom events to share data between components. Here is my Flex 3 Cookbook post on the topic:
    http://cookbooks.adobe.com/index.cfm?event=showdetails&postId=15466
    To switch easily between containers 1 & 2 use a ViewStack, the gold standard for such interaction, and manipulate the selectedIndex or selectedChild property:
    http://livedocs.adobe.com/flex/3/html/help.html?content=navigators_3.html
    If this post answered your question or helped, please mark it as such.

Maybe you are looking for

  • Error while invoking web service from PDK

    Hi, I had written code to invoke a sample web service which is generated through WSDL file. Started the web service and followed the sequence of steps that are described in this blog: https://www.sdn.sap.com/irj/sdn/weblogs?blog=/pub/wlg/2947. [origi

  • How do I turn off Home Sharing / Switch Back to Local Library?

    Last night I turned ON Home Sharing on my iPhone and switched (in the Music/iPod app) my library on the phone to use the Shared Library on my iMac.  It  works great and I have no issues, except... Now, that I am away from home (and my network), I am

  • Iweb website wont go on domain name

    i purchased a domain name from network solutions, and made my iweb website, which i will be hosting with mpbileme. i then changed the CNAME (alias) to web.me.com on www, and followed all the instructions, howevermy website has not been uploaded to th

  • [SOLVED] pacman -Qdt shows required packages

    I've used "pacman -Qdt" quite often but since yesterday it shows packages that it probably should not: autoconf2.13 hal pm-utils pm-quirks hal-info dmidecode consolekit xorg-server-xvfb yasm If I remove "orphans" like pm-utils or hal, I will only kno

  • How do i fix an error code -1202 please

    Hi Can anyone help with info on how to fix an error code -1202 please