Link to home
Start Free TrialLog in
Avatar of jmc430
jmc430

asked on

How do I send a primary key from one application to another and submit it in a form to the second application?

Greetings!

Does anyone know a minimally painful method to send a primary key from one application to another and submit it in a form to the second application?

I have two separate applications.  I feed the second application a primary key to generate PDF certificates on the fly with database driven data.  The first application contains a hard-coded hyperlink + the primary key (cPk), to connect to the second application.  Ultimately, the second application is a PDF generator, and the first application contains customized employee information (HR address, phone, dept stuff).

The hard-coded  hyperlink looked something like this:

http://hostname/someStuff/someMoreStuff/viewReport?=cPk

Due to security reasons (namely, the semblance of greater security with suppressed primary keys and the rigorous prevention of random certificate generation) we'd like to hide the cPk, yet still funnel over the cPk value from the first application to the second.

Can this be done via Javascript or Java?  Since the two applications perform very disparate functions, I would not like to consolidate both projects into one mega mess of code .. but it seems to be the only feasible way in my mind at this moment.

Any advice and or assistance would be greatly appreciated!

Best Regards,
Jamie
 
Avatar of griessh
griessh
Flag of United States of America image

Hi jmc430,

There are a couple of monitor apps out there. A commercial one with a 15 days trial is available at http://www.aggsoft.com/serial-port-monitor/

======
Werner
Sorry ... wrong question :-(
Avatar of Rick_Townsend
Rick_Townsend

If you want to hide the cPK variable, use POST instead of GET.  That is, where-ever you're pointing at the first app's hard-coded link, use a form to post the value of the primary key you generated (cPK).  Note that users won't be able to bookmark a link that doesn't have the PK in the url, because their bookmark won't resubmit the form data.
As for the main focus of your question:

Is the second app a webapp?  Or a system (server-side) app?  Or something else?  That affects how your second app can receive information sent from your first app.  I'm assuming that your first app is a webapp, since you're using a url.
Avatar of jmc430

ASKER

Hi Rick,

I was able to hide the first app's hard-coded URL by replacing the hyperlink itself with an image... but the second app opens with the same URL that I had initially suppressed in the first step.  How can I access the URL and hide it at the same time?

The second app is a webapp..

Thanks for your help!
Jamie



Ah, I understand better now.  The "hard-coded link" is a link in the first app to the second app.

Changing the link to a form post is probably still your best option.  That way you don't have to change the second app at all.

How you change the link first app depends on the type of page it is on.  Here are your options, based on language:
(NOTE: I named the url variable which is missing from your link "urlVar".  Replace that name and cPK with the correct values.)


HTML (and HTML variants, like SHTML and XML):

<form action="http://hostname/someStuff/someMoreStuff/viewReport" method="POST">
<input type="hidden" name="urlVar" value="cPK">
<input type="submit" src="yourImageURL">
</form>
JSP:

<html:form action="http://hostname/someStuff/someMoreStuff/viewReport" method="POST">
<html:image src="yourImageURL" property="urlVar" value="cPK"/>
</html:form>
Actually, that JSP example is fairly specific to Struts.  If you need a generic solution, the easiest is the HTML solution (since it all comes out that way in the end, anyways.)
Avatar of jmc430

ASKER

Hi,

I've currently got this code:

<form action="https://hostname/more/more/PDFGenerator/wa/viewReport" method="POST">
<input type="hidden" name="getCertificateUrl" value="cPk">
<input type="submit" src="getCertificateUrl">
</form>

I'd like the URL to also include the cPk value .. how can this be achieved?  It's accessing the main page of my second app, instead of creating the PDF on the fly (only going to the start page of the second app, "https://hostname/more/more/PDFGenerator/wa/viewReport").

THanks for your help!
jamie
Um, multiple things here:
The src attribute of the submit button should be the url of your image.  Otherwise, you get the ugly submit button.  But that's just a visual thing.
The value of the hidden input should be the value of cPk.  However you were generating the original url, do that here.
ex: <input type="hidden" name="getCertificateUrl" value="<%= cPk %>">
will do it in ASP or JSP.

I thought you wanted to hide the cPk value (ie, _not_ have it in the url box of the second app).  If you want it in the url of the second app, but don't want it to show up in the status bar of the first app when they mouse over a link, then use the form and set the action to your original url.
ex:
<form action="https://hostname/more/more/PDFGenerator/wa/viewReport?=cPk" method="POST">
<input type="submit" src="someImageURL">
</form>


If the goal is to remove the cPk value completely from the HTML of the first app, so that the user can't possibly see it, you need to have the first app establish some sort of connection to the second app (a secure pipe maybe, if security is a bug concern.)  Then you have the link in the first app launch an action that sends the cPk over the pipe, and forwards the user to the page on the second app.  However, if you want the cPk visible in the second apps location bar (url), I don't know why you'd hide it in the first one.
Avatar of jmc430

ASKER

I want to hide the cPk value so the user cannot possibly see it, in the first app and the second app.

The form action does not seem to be appending the certificate primary key values to access the PDF generator in the second app.

Here is my setup:

public String getCertificateURL(){
  String cPk = certification.certificationPk().toString();
  String url = "https://hostname/etc/etc/viewReport?cPk="+cPk;
  return url;
}

The value of the hyperlink is certificateURL.  The hyperlink connects directly to https://hostname/etc/etc/viewReport?cPk=cPk.  Only upon access to this URL will the PDF certificate be generated.  I was able to hide the value of the URL in the first app by binding the value of the hyperlink to an Active image instead.  With this binding, only the second app showed the full URL when it generated the PDF (on the fly).

When I used your code, I replaced my binding of the hyperlink to the Active image with the form HTML.

<form action="https://hostname/etc/etc/viewReport?" method="POST">
<input type="hidden" name="getCertificateURL" value="<%=cPk%">
<input type="submit">

However, when I tried using this .. the form only appears to directly connect to the following URL:

https://hostname/etc/etc/viewReport

without accessing the second app's certificate PDF generation via the hard-coded link certificateURL, https://hostname/etc/etc/viewReport?cPk=cPk.

Is it feasible to hope that the second app can indeed hide the URL and generate the PDF certificate simultaneously?

I'm sorry for being incoherent .. I really appreciate your help.

Thanks so much,
jamie

Yes, it is feasible.  BTW, if you use a link or form action with the cPk value, it _will_ be visible to the user if they look at the source of the web page.  If that is a security concern, we can start talking about alternatives like pipes and servlet-to-servlet https messages.

If that isn't a concern, then lets continue.
Ok, the reson the form isn't working is that you put in the wrong variable name.  If your url is http://blah/page?cPk=value then "cPk" is the name of the url variable that the second app is expecting.  Try this code:

<form action="https://hostname/etc/etc/viewReport?" method="POST">
<input type="hidden" name="cPk" value="<%=cPk%">
<input type="submit">
However, if cPk isn't a local variable on your JSP page (I assume JSP because of the Java code for getCertificateURL), then you need to call that method.  Is the method defined in that JSP page itself, in a bean used on that page (look for a usebean declaration), or in a class file that is imported (look for a <%page import ... %> statement).

In the JSP:
<form action="https://hostname/etc/etc/viewReport?" method="POST">
<input type="hidden" name="cPk" value="<%=getCertificateURL()%">
<input type="submit">

In a bean (say the bean is given the name "myBean"):
<form action="https://hostname/etc/etc/viewReport?" method="POST">
<input type="hidden" name="cPk" value="<%=myBean.getCertificateURL()%">
<input type="submit">

In another class that is imported (say the object created from that class is called "myObject"):
<form action="https://hostname/etc/etc/viewReport?" method="POST">
<input type="hidden" name="cPk" value="<%=myObject.getCertificateURL()%">
<input type="submit">
Avatar of jmc430

ASKER

I keep getting the following error:

Error:         java.lang.NumberFormatException: For input string: "%=cPk%"
Reason:       For input string: "%=cPk%"

although I got the following code in place:

public Double getCPk(){
   return cPk;
}

public void setCPk(String newCPk){
  cPk = new Double(new CPk)
}

What am I doing wrong?
Avatar of jmc430

ASKER

here is the error that i am getting:

Application:         PDFGenerator
Error:       java.lang.NumberFormatException: For input string: "<%cPk%>"
Reason:       For input string: "<%cPk%>"
Stack trace:       

File       Line#       Method       Package
NumberFormatException.java       48       forInputString       java.lang
FloatingDecimal.java       1207       readJavaFormatString       java.lang
Double.java       202       valueOf       java.lang
Double.java       277       <init>       java.lang
PrivacyCertificate.java       106       setCPk       PrivacyCertificate
GeneratedMethodAccessor22.java       NA       invoke       sun.reflect
DelegatingMethodAccessorImpl.java       25       invoke       sun.reflect
Method.java       324       invoke       java.lang.reflect
KeyValueCodingProtectedAccessor.java       65       setMethodValue       KeyValueCodingProtectedAccessor
NSKeyValueCoding.java       1175       setValueInObject       com.webobjects.foundation
NSKeyValueCoding.java       1293       takeValueForKey       com.webobjects.foundation
WOComponent.java       1550       takeValueForKey       com.webobjects.appserver
BasePage.java       34       takeFormValues       BasePage
PDFReportGenerator.java       12       getReport       PDFReportGenerator
DirectAction.java       28       viewReportAction       DirectAction
GeneratedMethodAccessor14.java       NA       invoke       sun.reflect
DelegatingMethodAccessorImpl.java       25       invoke       sun.reflect
Method.java       324       invoke       java.lang.reflect
WODirectAction.java       128       performActionNamed       com.webobjects.appserver
WOActionRequestHandler.java       240       _handleRequest       com.webobjects.appserver._private
WOActionRequestHandler.java       142       handleRequest       com.webobjects.appserver._private
WOApplication.java       1306       dispatchRequest       com.webobjects.appserver
WOWorkerThread.java       173       runOnce       com.webobjects.appserver._private
WOWorkerThread.java       254       run       com.webobjects.appserver._private
Thread.java       552       run       java.lang
NA : Non applicable, JIT activated

(i'm using webobjects ...)

i tried modifying the type for the cPk to Double (which is what the PDF Generator is looking for) to no avail ...

any help or advice would be greatly appreciated!

jamie
ASKER CERTIFIED SOLUTION
Avatar of Rick_Townsend
Rick_Townsend

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of jmc430

ASKER

Here is the relevant HTML source of the generated page
==========================================================================================
<TABLE WIDTH="563" BORDER="0" CELLSPACING="0" CELLPADDING="5" bgcolor="#CCCCCC">
                                        <TR>
                                                <TD VALIGN=top>
                                                        <TABLE CELLSPACING="0" BORDER="0" WIDTH="553" CELLPADDING="2">
                                                        <TR>

                                                                <td valign="top"><font size="1" face="verdana,arial,helvetica,sans-serif"><b>Status</b></font></t
d>
                                                                <td valign="top"><font size="1" face="verdana,arial,helvetica,sans-serif"><b>Name</b></font></td>
                                                                <td valign="top"><font size="1" face="verdana,arial,helvetica,sans-serif"><b>Grade</b></font></td
>
                                                                <td valign="top"><font size="1" face="verdana,arial,helvetica,sans-serif"><b>Exp Date</b></font><
/td>
                                                                <td valign="top"><font size="1" face="verdana,arial,helvetica,sans-serif"><b><a href="/etc/etc/etc/wo/blah">Refetch</a></b></font></td>
                                                        </TR>

                                                        <TR>

                                                                <td valign="top"><font size="1" face="verdana,arial,helvetica,sans-serif">approved</font></td>
                                                                <td valign="top"><font size="1" face="verdana,arial,helvetica,sans-serif">HIPAA security training
 </font></td>
                                                                <td valign="top"><font size="1" face="verdana,arial,helvetica,sans-serif"></font></td>
                                                                <td valign="top"><font size="1" face="verdana,arial,helvetica,sans-serif">None</font></td>
                                                        <TD>
<form action="https://hostname/etc/etc/viewReport?cPk" method="POST">
        <input TYPE="hidden" NAME="cPk" VALUE="<%=cPk%>"><input type="submit"></form><a target="_blank" href="http://hostname/etc/tra_ins.html"
>Certification Training</a></TD>
                                                        </TR>

                                                        <TR>

                                                                <td valign="top"><font size="1" face="verdana,arial,helvetica,sans-serif">approved</font></td>
                                                                <td valign="top"><font size="1" face="verdana,arial,helvetica,sans-serif">Testem </font></td>
                                                                <td valign="top"><font size="1" face="verdana,arial,helvetica,sans-serif"></font></td>
                                                                <td valign="top"><font size="1" face="verdana,arial,helvetica,sans-serif">October 25, 2005</font>
</td>
                                                        <TD>
<form action="https://hostname/etc/etc/viewReport?cPk" method="POST">
        <input TYPE="hidden" NAME="cPk" VALUE="<%=cPk%>"><input type="submit"></form><a target="_blank">Certification Training</a></TD>
                                                        </TR>

                                                        <TR>

                                                                <td valign="top"><font size="1" face="verdana,arial,helvetica,sans-serif">approved</font></td>
 <td valign="top"><font size="1" face="verdana,arial,helvetica,sans-serif">Computing </fon
t></td>
                                                                <td valign="top"><font size="1" face="verdana,arial,helvetica,sans-serif"></font></td>
                                                                <td valign="top"><font size="1" face="verdana,arial,helvetica,sans-serif">None</font></td>
                                                        <TD>
<form action="https://hostname/etc/etc/viewReport?cPk" method="POST">
        <input TYPE="hidden" NAME="cPk" VALUE="<%=cPk%>"><input type="submit"></form><a target="_blank" href="http://hostname">Certificate Training</a></TD>
                                                        </TR>

                                                        <TR>

                                                                <td valign="top"><font size="1" face="verdana,arial,helvetica,sans-serif">pending</font></td>
                                                                <td valign="top"><font size="1" face="verdana,arial,helvetica,sans-serif">bbbbbb </font></td>
                                                                <td valign="top"><font size="1" face="verdana,arial,helvetica,sans-serif"></font></td>
                                                                <td valign="top"><font size="1" face="verdana,arial,helvetica,sans-serif"></font></td>
                                                        <TD><a target="_blank" href="https://asdfasdfasdf">Certification Training</a></TD>
                                                        </TR>

                                                        </TABLE>
                                                </TD>
                                        </TR>
                                        </TABLE>
==========================================================================================
Is seems like it is not getting the value of cPk .. how can I fix this?
Avatar of jmc430

ASKER

Hi Rick,

Thanks for your assistance and patience with me.  I appreciate your help!

=)
Glad you got it figured out.