Solved

POST function in FORM (embedded in a java class on webobjects)

Posted on 2004-10-05
12
257 Views
Last Modified: 2008-01-09
Greetings,

I'm trying to get this bit of code working:

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

I would like this to append the URL with the cPk value .. but I keep getting this error:

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

Any ideas?

Your help would be greatly appreciated.

Best Regards,
Jamie

0
Comment
Question by:jmc430
12 Comments
 
LVL 27

Expert Comment

by:Diablo84
ID: 12232312
I would have though this should have gone in the Java Ta but prehaps the error is a missing diamond bracket?

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

Author Comment

by:jmc430
ID: 12232357
I tried that already ...
0
 
LVL 6

Expert Comment

by:snavebelac
ID: 12232413
<form action="https://hostname/etc/etc/etc/viewReport?cPk=<%=cPk%>" method="POST">
<input type = "submit">

make sure your pages have the correct extension otherwise the server side parts will not get processed.  I am assuming this is ASP ? in which case the pages need to be whaatever.asp

HTH

C
0
 
LVL 1

Expert Comment

by:MMabatig
ID: 12233118
Hello jmc430,

If you are bound to using post as the method, then snavebelac's method is one way you can go.  However, if the end goal is to have the values of one or more <input> tags automatically appended to the end of the URL listed in the "action" property of a form, then you can use the following code:

<form action="https://hostname/etc/etc/etc/viewReport.asp" method="GET">
<input type ="hidden" name="cPk" value="<%=cPkValue%>">
<input type ="hidden" name="cPk2" value="<%=cPkValue2%>">
<input type ="hidden" name="cPk3" value="<%=cPkValue3%>">
<input type = "submit">

Notice that the method is not "POST" but rather "GET".   When this form is submitted, then the resulting url the user will be sent to is:

https://hostname/etc/etc/etc/viewReport.asp?cPk=cPkValue&cPk2=cPkValue2&cPk3=cPkValue3

Keep in mind that doing this will show the variable names and values in the location bar of the users browser (if it is visible).

Hope this helps!

-Mark
0
 

Author Comment

by:jmc430
ID: 12237076
Hi Mark,

Is there a way to do it so that the variable names and values are kept hidden from the location bar of the users browser?

Thanks!
jamie
0
 
LVL 6

Expert Comment

by:snavebelac
ID: 12237505
You will have to use a POST form method so that the variables are not appended to the URL.

<form action="https://hostname/etc/etc/etc/viewReport.asp" method="POST">
<input type ="hidden" name="cPk" value="<%=cPkValue%>">
<input type ="hidden" name="cPk2" value="<%=cPkValue2%>">
<input type ="hidden" name="cPk3" value="<%=cPkValue3%>">
<input type = "submit">

C
0
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 

Author Comment

by:jmc430
ID: 12237791
I seem to be getting errors in my URL ...

https://hostname/etc/etc/etc/viewReport?cPk=%3C%25%3DgetCertificateUrl%25%3E

where 'getCertificateUrl' was the cPkValue.

I used

<input type="hidden" name="cPk" value="<%=getCertificateURL%>">

Thanks so much for your help ...
0
 
LVL 6

Expert Comment

by:snavebelac
ID: 12238430
The %3c%25%3 is the encoding of <%=  This means that the code is not being processed server side.

Make sure you file is named viewreport.ASP so that the server side scriting components are processed.

Could you also verify that it is ASP you are using.  that is what it looks like to me but it could ASP.NET I suppose.  Also, if you have your method sent to GET the values will be appended to the URL, with POST they will not.

C
0
 

Author Comment

by:jmc430
ID: 12239884
oh .. i changed that ..

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 ...

jamie
0
 
LVL 6

Expert Comment

by:snavebelac
ID: 12240057
I think your reasoning is correct in that the datartype of cPk is incorrect.  Could you post the code for the entire page please.  This will greatly help in resolving the problem I am sure

C
0
 

Author Comment

by:jmc430
ID: 12240263
here is the entire code for Certifications.java:
=============================================================================================
public class Certifications extends WOComponent {
    protected NSArray certList;
    protected Certification certification;
    protected String user_cwid;
    protected Double cPk;

    public Certifications(WOContext context) {
        super(context);
        user_cwid = ((Session)session()).user_cwid;  //Get CWID from REMOTE_USER
        initComponent();
    }

    public WOComponent initComponent() {
        if (user_cwid == null) return null;

        //PersonPK Fetch
        NSDictionary personbindings = new NSDictionary( new Object [] { user_cwid }, new Object [] { "cwidvalue" } );
        EOFetchSpecification personfetchSpec = EOFetchSpecification.fetchSpecificationNamed("personPkFetchSpec", "VPerson");
        personfetchSpec = personfetchSpec.fetchSpecificationWithQualifierBindings(personbindings);
        EOEditingContext personEC = this.session().defaultEditingContext();
        NSArray personList = personEC.objectsWithFetchSpecification(personfetchSpec);
        if (personList.count() != 1) return null;

        //Certification Fetch
        VPerson person = (VPerson)personList.objectAtIndex(0);
        Number personPkvalue = person.personPk();

        NSDictionary certbindings = new NSDictionary( new Object [] { personPkvalue }, new Object [] { "personPkvalue" } );
        EOFetchSpecification certfetchSpec = EOFetchSpecification.fetchSpecificationNamed("certFetchSpec", "Certification");
        certfetchSpec = certfetchSpec.fetchSpecificationWithQualifierBindings(certbindings);
        EOEditingContext certEC = this.session().defaultEditingContext();
        certList = certEC.objectsWithFetchSpecification(certfetchSpec);

        return null;
    }

   public WOComponent refetch() {
        this.session().defaultEditingContext().invalidateAllObjects();
        return null;
    }

    public boolean getIsPending() {
        String certStatus = certification.status();
        if (certStatus.equals("pending")) return true;
        else return false;
    }


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

    public Double getCPk() {
        return cPk;
    }

    public void setCPk(String getCertificateUrl) {
        cPk = new Double(getCertificateUrl);
    }

}
=============================================================================================
here is the code for PrivacyCertificate:
=============================================================================================
public class PrivacyCertificate extends BasePDFReport {

    public String aKey;
    protected Double cPk;
    protected String dept;
    protected String date;
    protected String name;
    protected VPerson person;
    protected VPerson department;
    protected WODisplayGroup PrivacyCertificate;
    protected String user_cwid;
   
    static List depts;
       
    public PrivacyCertificate(WOContext context) {
        super(context);
        user_cwid = ((Session)session()).user_cwid;
    }
   
    public void fetchDepartName()  
    {    
        Session s = ((Session)session());
        String strCount = " ";
        String sql = new String("select distinct CERTIFICATE_NAME from people_db.CERTIFICATE, people_db.CERTIFICATION");
        sql += " where CERTIFICATION.CERTIFICATION_PK =  '" + cPk + "' ";
        sql += " and CERTIFICATE.CERTIFICATE_PK = CERTIFICATION.CERTIFICATE_FK";

        NSArray results = EOUtilities.rawRowsForSQL(session().defaultEditingContext(),  "PeopleCertification", sql);
                                               
        if (results != null && results.count() > 0) {
            NSLog.out.appendln("CERTIFICATE_PK " + cPk + sql);
            NSDictionary values =  (NSDictionary)results.objectAtIndex(0);
            Object obj = values.objectForKey("CERTIFICATE_NAME");
            strCount = obj.toString();
      }
        setReportName(strCount);
     }

    public WOComponent generateReport() {
        if (cPk != null && (dept == null || date == null || name == null)) {
        NSArray foundCert = lookupCertification();
        RMDocument template = new RMWODocument("CERTIFICATE");
        RMDocument report= template.generateReport(foundCert);
        RMWOPage nextPage = (RMWOPage)pageWithName("RMPDFPage");
                nextPage.document = report;
                       
        fetchDepartName();
        reportName = reportName.replaceAll("[^a-zA-Z0-9]", "");
        nextPage.filename = reportName+".pdf";
        return nextPage;
         }
       
        else if (dept!=null && name!= null && date!=null)  {
            Map certificate = new RMXMLReader().read("BundleResource:Certificate2.xml");
            Map userInfo = new Hashtable();
            userInfo.put("dept",getDept());
            userInfo.put("name",getName());
            userInfo.put("date",getDate());
                   
           RMDocument template = new RMWODocument("RPM");
           RMDocument report = template.generateReport(certificate.get("certificate"), userInfo, true);
           RMWOPage page = (RMWOPage)pageWithName("RMPDFPage");
           page.document = report;
           return page;  
        }
        else    {
            return null;
        }

    }
             
     private NSArray lookupCertification() {      
        // Lookup Certification via cPk
        return fetchSearch("getCertificationPk", "Certification", "cPk", getCPk(), this.session().defaultEditingContext());
    }
   
    public Double getCPk() {
        return cPk;      
    }

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

    public String getName() {
        return name;
    }    
   
    public void setName(String newName){
        name = newName;
    }
       
    public String getDept(){
        return dept;
    }
   
    public void setDept(String newDept){
        dept = newDept;
    }
   
    public String getDate(){
        return date;
    }
   
    public void setDate(String newDate){
        date = newDate;
    }  

      private NSArray fetchSearch(String fName, String entity, String key, Number value, EOEditingContext ec) {
      // retrieve service pks for the current heading
      EOFetchSpecification fetchSpec = EOFetchSpecification.fetchSpecificationNamed(fName, entity);
     // Reset parentValue in the query string
      NSMutableDictionary dict = new NSMutableDictionary();
      dict.setObjectForKey(value, key);
      fetchSpec = fetchSpec.fetchSpecificationWithQualifierBindings(dict);

      // Query the database with parentValue
      NSArray result = ec.objectsWithFetchSpecification(fetchSpec);

      return result;
   }
   
    public NSArray getValueList() {
        return ((new NSArray (new Object[] { "cPk", "name", "dept", "date" })));
    }
}
=============================================================================================
here is the relevant code for BasePage:
=============================================================================================
 public void takeFormValues(NSDictionary value) {
        java.util.Enumeration e = getValueList().objectEnumerator();

        while (e.hasMoreElements()) {
            String key = (String)e.nextElement();

            Object obj = context().request().formValueForKey(key);
            if (obj != null) {
                takeValueForKey(obj, key);
            }
        }
    }
=============================================================================================
and I have this form html embedded:

<input TYPE="hidden" name="cPk" VALUE="<%getCertificateUrl()%>">

(also tried different variations of cPk, certificateUrl, url, with and without diamon brackets...

thanks so much for your help!  i really appreciate it.

jamie
0
 
LVL 6

Accepted Solution

by:
snavebelac earned 250 total points
ID: 12240483
<input TYPE="hidden" name="cPk" VALUE="<%getCertificateUrl()%>">

needs to be

<input TYPE="hidden" name="cPk" VALUE="<%=getCertificateUrl()%>">

Other than that, the java parts are a little beyond me I am afraid.

Perhaps it would be wise to ask for this question to be moved to the Java forum or post a minimum point question that links here.

Sorry I could not be of any more help...I am cetain someone here will be able to sort it for you.

C

0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

SASS allows you to treat your CSS code in a more OOP way. Let's have a look on how you can structure your code in order for it to be easily maintained and reused.
This article discusses how to create an extensible mechanism for linked drop downs.
In this tutorial viewers will learn how to position overlapping items using z-index in CSS. They will also learn the restrictions on the z-index property.  Create a new HTML document with an internal stylesheet.: Create a div in CSS and name it Red.…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)

708 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now