Doubt in loosely coupled interaction with J2EE app

gomashan07
User offline. Last seen 9 weeks 4 days ago. Offline
Joined: 01/27/2011
Points: 251

Hi all,

   This is the JSp page

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
<form action="servlet " method="POST">
        First Name: <input type="text" name="firstName" size="20"><br>
        Surname: <input type="text" name="surname" size="20">
        <br><br>
        <input type="submit" value="Submit">
    </form>
</body>
</html>

          I have 2 doubts .

1. How will i pass a value from presto app to a J2EE application. If the method is GET in servlet then we can use the URL to send the parameter like localhost://sample?username=prestovalue. What can i do if there is no parameter in the URL. How can i pass vaue when the method is POST in  servlet.

2. IS there anyway for  this JSP to publish a value and make a custom presto app subscribe and using it.

 

Please help me

 

0
Your rating: None
gomashan07
User offline. Last seen 9 weeks 4 days ago. Offline
Joined: 01/27/2011
Points: 251

Let me make it more clear . I want an idea how to make an j2ee web app publish a value and a presto custom app should subscribe to that. Hope there is a mechanism that supports this.

The second question is when the form parameters are displayed in the URL we can make the custom  app interact with the web app by  using the URL(which contains the form parameter)  in the html() function and rendering it with that. But if the form parameters  are not displayed in the URL how can the custom app use value from the web app .

 

gomashan07
User offline. Last seen 9 weeks 4 days ago. Offline
Joined: 01/27/2011
Points: 251

 Kindly some one help me out . I  need an answer for this to proceed further in my project :(

gomashan07
User offline. Last seen 9 weeks 4 days ago. Offline
Joined: 01/27/2011
Points: 251

Is the scenario  such that i should use PC4JS api to accomplish this task ..

smitchell
smitchell's picture
User offline. Last seen 2 weeks 5 days ago. Offline
Joined: 08/29/2008
Points: 34

I'm still a little confused about how this all is supposed to work together. Are you embedding a custom App in the JSP page? Or is the JSP page embedded in an iframe in a page where the custom App is also embedded?

Sara, technical writer/jackbe

 

gomashan07
User offline. Last seen 9 weeks 4 days ago. Offline
Joined: 01/27/2011
Points: 251

Hi ,

    I will explain you clearly the scenario . kindly read it patiently. My task is i have a JSP and servlet. When i enter the name  in the text box in JSP , the  GET method in servlet displays the name. In the JSP page  <form action >  tag there is a attribute called method when that method is set to GET . The url  will have form parameters. Eg: http://localhost:7087/simpleapp/formproc1?param=ram.  If this is the case i can  use 

root.html('<iframe style="width:'+w+'px;height:'+h+'px;" ' +  'src=http:/path-to-my-jsp/myjsp.jsp?documentId="'+doc+'" ></iframe>')
 

 

But when i use the POST value in  method attribute of <formaction >  tag the url  will not have parameters . eg http://localhost:7087/simpleapp/formproc1 if this is the case how can i  make the the JSP page run according to my inputs from presto .

This is the end of first question .

i will now explain the second question

                                                              The second question is i am  passing the value from JSP  to servlet and it gets displayed there. Is there  anyway i can intercept the values  and Get that value in presto custom app.

 

 

jeremy.pitten
jeremy.pitten's picture
User offline. Last seen 5 weeks 3 days ago. Offline
Joined: 09/22/2008
Points: 275

You need to process your form data on the server side. Your sample.jsp can use the Java method request.getParameter whether the form was submitted using post or get. So for example I could take the surname form input and pass it as a parameter to a second app using :

            <script  src="/prestohub/mashlet/hello-world?helloString=<%=request.getParameter("surname")%>"></script>

You could do the equivalent in a servlet, using the request.getParameter method.

 

gomashan07
User offline. Last seen 9 weeks 4 days ago. Offline
Joined: 01/27/2011
Points: 251

If my J2EE web app runs like this http://localhost:7087/simpleapp/formproc1?param=ram.   I mean the url  has parameters . Then i can use 

root.html('<iframe style="width:'+w+'px;height:'+h+'px;" ' +  'src=http:/path-to-my-jsp/myjsp.jsp?documentId="'+doc+'" ></iframe>');  to dembed the j2ee app in my mashboard and run according to the input from presto.Here  the input doc comes from presto app.  

My doubt is if the web app runs in  this format http://localhost:7087/simpleapp/formproc1  how  do  i embed the web app and in  my mashboard and pass my own . Assume i want to pass this value doc(which is a presto app value ) as  input to the  web app  . In the last type we accomplished  this task by changing the form parameters in the url apending the value doc in to the url.  How can  we do  it now  in the second type http://localhost:7087/simpleapp/formproc1. Thanks in advance

gomashan07
User offline. Last seen 9 weeks 4 days ago. Offline
Joined: 01/27/2011
Points: 251

MY doubt is does ur answer actually meant for the second question. Kindly help me .

gomashan07
User offline. Last seen 9 weeks 4 days ago. Offline
Joined: 01/27/2011
Points: 251

  When the  J2EE app  runs with the following  URL http://localhost:7087/simpleapp/formproc1?param=ram  i can  access and embed passing the parameter from presto using

root.html('<iframe style="width:'+w+'px;height:'+h+'px;" ' +  'src=http:/path-to-my-jsp/myjsp.jsp?documentId="'+doc+'" ></iframe>');

here  is doc is a presto parameter.

 

IF the URL is of the form http://localhost:7087/simpleapp/formproc1  here parameters are not  displayed in URL.  How to embed the j2EE app  with presto parameters . i want a solution for this .

jeremy.pitten
jeremy.pitten's picture
User offline. Last seen 5 weeks 3 days ago. Offline
Joined: 09/22/2008
Points: 275

You could use jQuery.post and if the post response is a web page you could write the response into an iframe, something like this:

Sample.MySimpleApp = function( app ) {
    var  iframe = document.createElement("iframe");
    iframe.style.width = "100%";
    iframe.style.height = "100%";
    app.getContentEl().appendChild(iframe);

    app.subscribe('my.topic', function(topic, msg){
        jQuery.post('http://localhost:7087/simpleapp/formproc7', msg,
            function(html){
                var doc = iframe.contentWindow.document;   
                 doc.write(html);
                 doc.close();
            });
    }); };

 

gomashan07
User offline. Last seen 9 weeks 4 days ago. Offline
Joined: 01/27/2011
Points: 251

Hi,

  Thanks for the answer ...

Kindly  help me with a answer for this question .. pls ..Its quiet urgent

When the  J2EE app  runs with the following  URL http://localhost:7087/simpleapp/formproc1?param=ram  i can  access and embed passing the parameter from presto using

root.html('<iframe style="width:'+w+'px;height:'+h+'px;" ' +  'src=http:/path-to-my-jsp/myjsp.jsp?documentId="'+doc+'" ></iframe>');

here  is doc is a presto parameter.

 

IF the URL is of the formhttp://localhost:7087/simpleapp/formproc1  

 Here parameters are not  displayed in URL.  How to embed the j2EE app  with presto parameters . i want a solution for this .

jeremy.pitten
jeremy.pitten's picture
User offline. Last seen 5 weeks 3 days ago. Offline
Joined: 09/22/2008
Points: 275

In the example I gave above the presto app parameters can be carried in the jquery post payload. In the example below the Sample.MySimpleApp subscribes to a topic named "my.topic", when this topic event is received, if it carries a doc property it is added to the POST payload data.

Sample.MySimpleApp = function( app ) {
    var  iframe = document.createElement("iframe");
    iframe.style.width = "100%";
    iframe.style.height = "100%";
    app.getContentEl().appendChild(iframe); var data = { width:200, height, 100, documentId: 'ram' }; app.subscribe('my.topic', function(topic, msg){ if(msg.doc){ data.documentId = msg.doc; jQuery.post('http://localhost:7087/simpleapp/formproc1', data, function(html){ var doc = iframe.contentWindow.document; doc.write(html); doc.close(); }); } }); };
 
The jQuery.post will invoke your simpleapp/formproc1 JSP which must then extract the presto parameter data from the request POST payload using request.getParameter method on the server side, for example:
 
<%@page contentType="text/html" pageEncoding="MacRoman"%>
<%
    String height = request.getParameter("height");
    String width = request.getParameter("width");
    String doc = request.getParameter("documentId");
%>
<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=MacRoman">
        <title>My JSP</title>
        <script type="text/javascript" src="/presto/hub/third-party/jquery/1.6.2/jquery.min.js"></script>
    </head>
    <body>
        <div id='root'></div>
        <script>
            var root = jQuery('#root'),
            h = <%=height%>,
            w = <%=width%>,
            doc = '<%=doc%>';
            root.html('<iframe style="width:'+w+'px;height:'+h+'px;" ' +  'src=http:/path-to-my-jsp/myjsp.jsp?documentId="'+doc+'" ></iframe>'); 
        </script>
    </body>
</html>