Hello, I am new to XSP in Cocoon.  I am experimenting
with a way to POST to a servlet, but not using the
name-value pair combination shown in the CInclude
(advanced) example.

To me XSP seems to not like the typecasting -
parenthesis syntax required by Java.  It sees the
parenthesis, and gives an error.  JSP handles similar
code with no problem.  Is this a bug?  I get an
Internal Service Error,

URL url = new URL(specURL);
HttpURLConnection httpConn = (HttpURLConnection)
url.openConnection(); 

// start error (lines 83-83) "Syntax error on token
"(", "Identifier" expected"

Here is the full xsp listing:

<?xml version="1.0" encoding="ISO-8859-1"?>

<xsp:page language="java"
  xmlns:xsp="http://apache.org/xsp";
 
xmlns:cinclude="http://apache.org/cocoon/include/1.0";
 
xmlns:xsp-session="http://apache.org/xsp/session/2.0";
>

<xsp:structure>
        <xsp:include>java.net.URL</xsp:include>
        <xsp:include>java.net.HttpURLConnection</xsp:include>
        <xsp:include>java.io.OutputStreamWriter</xsp:include>
        <xsp:include>java.io.BufferedReader</xsp:include>
        <xsp:include>java.io.InputStreamReader</xsp:include>
</xsp:structure>

<xsp:logic>
        StringBuffer results = new StringBuffer();
        String specURL = "SOMESERVERURL";
        String specStr = "&lt;SOMEXML /&gt;";
        URL url = new URL(specURL); 
        HttpURLConnection httpConn = (HttpURLConnection)
url.openConnection(); 
    httpConn.setDoInput(true); 
    httpConn.setDoOutput(true); 
    httpConn.setRequestMethod("POST"); 
    httpConn.setUseCaches(false); 
    httpConn.setDefaultUseCaches(false); 

httpConn.setRequestProperty("content-type","application/x-www-form-urlencoded");

httpConn.setRequestProperty("content-length",String.valueOf(specStr.length()));

    
    OutputStreamWriter connWriter = new
OutputStreamWriter( httpConn.getOutputStream() );
    connWriter.write(specStr);
    connWriter.flush();
        connWriter.close();
    
    httpConn.connect();
    
        int responseCode = httpConn.getResponseCode();
        String responseMsg = httpConn.getResponseMessage();
        BufferedReader br = new BufferedReader(new
InputStreamReader(httpConn.getInputStream()));
        String oneline;
        while ( (oneline = br.readLine()) != null) {
                 results.append(oneline);
        }
        br.close();
</xsp:logic>
<xsp:expr>results.toString()</xsp:expr>
</xsp:page>

__________________________________
Do you Yahoo!?
Yahoo! Search - Find what you�re looking for faster
http://search.yahoo.com

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to