Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

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

Posted on 2004-10-05
20
Medium Priority
?
323 Views
Last Modified: 2010-04-17
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
 
0
Comment
Question by:jmc430
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 10
  • 7
  • 3
20 Comments
 
LVL 11

Expert Comment

by:griessh
ID: 12230170
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
0
 
LVL 11

Expert Comment

by:griessh
ID: 12230202
0
 
LVL 11

Expert Comment

by:griessh
ID: 12230209
Sorry ... wrong question :-(
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 4

Expert Comment

by:Rick_Townsend
ID: 12230364
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.
0
 
LVL 4

Expert Comment

by:Rick_Townsend
ID: 12230393
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.
0
 

Author Comment

by:jmc430
ID: 12230474
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



0
 
LVL 4

Expert Comment

by:Rick_Townsend
ID: 12230736
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>
0
 
LVL 4

Expert Comment

by:Rick_Townsend
ID: 12230837
JSP:

<html:form action="http://hostname/someStuff/someMoreStuff/viewReport" method="POST">
<html:image src="yourImageURL" property="urlVar" value="cPK"/>
</html:form>
0
 
LVL 4

Expert Comment

by:Rick_Townsend
ID: 12230890
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.)
0
 

Author Comment

by:jmc430
ID: 12230968
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
0
 
LVL 4

Expert Comment

by:Rick_Townsend
ID: 12231146
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.
0
 

Author Comment

by:jmc430
ID: 12231308
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

0
 
LVL 4

Expert Comment

by:Rick_Townsend
ID: 12231436
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">
0
 
LVL 4

Expert Comment

by:Rick_Townsend
ID: 12231485
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">
0
 

Author Comment

by:jmc430
ID: 12231602
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?
0
 

Author Comment

by:jmc430
ID: 12239892
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
0
 
LVL 4

Accepted Solution

by:
Rick_Townsend earned 2000 total points
ID: 12240770
I suspect it's returning this error because the form is submitting the string "<%cPk%>" for the variable cPk, instead of the value.

View the HTML source of your page with the form tag (ie: the page in app 1).  It should have the _value_ of the primary key in the value="" attribute.  Post the generated HTML source here (remember to alter the action="" string so you aren't sharing it with everyone who reads this.)
0
 

Author Comment

by:jmc430
ID: 12240947
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?
0
 

Author Comment

by:jmc430
ID: 12241338
Hi Rick,

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

=)
0
 
LVL 4

Expert Comment

by:Rick_Townsend
ID: 12243641
Glad you got it figured out.
0

Featured Post

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Although it can be difficult to imagine, someday your child will have a career of his or her own. He or she will likely start a family, buy a home and start having their own children. So, while being a kid is still extremely important, it’s also …
What do responsible coders do? They don't take detrimental shortcuts. They do take reasonable security precautions, create important automation, implement sufficient logging, fix things they break, and care about users.
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
Starting up a Project

636 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question