How can i call a CGI script from java?
The subject pretty much says it all. I want to call a perl cgi script so i can read from/write to files on a server. I don't know how to sign applets and this would be the easiest way for me, if someone could please tell me.
Let me get this clear. Basically what u want to do is to just call a URL, right?
U can do it by using the following code:
import java.applet.*;
import java.net.*;
import java.io.*;
public class testhttp
public static void main(String[] args)
try
URL url = new URL ("http://../testcgi.cfm");
HttpURLConnection cxn =
(HttpURLConnection)url.openConnection();
cxn.setRequestMethod("POST");
cxn.setUseCaches(false);
cxn.setDoOutput(true);
cxn.setDoInput(true);
ByteArrayOutputStream bytes = new
ByteArrayOutputStream(400);
PrintWriter writer = new PrintWriter (bytes,true);
writer.print("application=map&release=1&items=prog1");
writer.flush();
cxn.setRequestProperty("Content-
Length",String.valueOf(bytes.size()));
cxn.setRequestProperty("Content-
Type","application/x-www-form-urlencoded");
bytes.writeTo(cxn.getOutputStream());
System.out.println(bytes);
String currentLine;
BufferedReader in = new BufferedReader (new
InputStreamReader(cxn.getInputStream(),"8859_1"));
while((currentLine = in.readLine()) != null) {
System.out.println(currentLine); }
catch(Exception e) { e.printStackTrace(); }
There is also a library called HTTP client which can be found at:
http://www.innovation.ch/java/HTTPClient/index.html
It's very simple to use and the documentation is all there, but their web server seems to be down right now.
Anyway, hope my post helps.
Similar Messages
-
Can any one tell me how can i call a shell script from pl/sql
i like to call shell script from pl/sql procedure.
can any one suggest how can i do thisHave you not mastered in asking the same kind of question ?
First do write a script...
no one will spoon feed you.
How can i call a shell script from procedure
How to call Shell Script from pl/sql block
-Sk -
How can i call a shell script from procedure
I have a shell script.now i am i a situation to call that shell script from one of my procedures and need to get a value from that script.
can u suggest me that how can a call the shell script from pl/sql?Is the same question you asked here
How to call Shell Script from pl/sql block
-SK -
How can i call forpro prg file from java
Hai friends,
I have a doubt,clear it.
how can i call forpro prg file from java file
by,
N.VijayThanks to your reply,
I have some print statements in my foxpro program file.
Then i like to invoke that foxpro file from my java file
This want i want..,
by,
N.Vijay -
How can I call a hsqldb procedure from Java
Hello,
I am trying to call from Java a stored procedure but I keep having exceptions!!!
In addition, I have no idea how I can get the result of the procedure !!!!
I have spent the whole day in Internet.... no luck!!
===============================================
I[b] java.lang.Exception: +updatejava.sql.SQLException: Unexpected token: # in statement [ call MODIFY_FIELD_SEPARATOR(#) ]
at util.UtilBean.test_upd(UtilBean.java:369)
===============================================
The following procedures have been created and tested withing the database and there work.
- public static String manage_field_separator(String ifs)
-public static String manage_refresh_interval(int val)
The alias have been created:
CREATE ALIAS MODIFY_FIELD_SEPARATOR FOR "com.lucent.util.StoredProcedures.manage_field_separator";
CREATE ALIAS MODIFY_REFRESH_INTERVAL FOR "com.lucent.util.StoredProcedures.manage_frefresh_interval
My file.java contains the flollowing:
public String test_upd(String tableName, String paramValue)
throws Exception
String res="0";
Connection conn=null;
CallableStatement cs= null;
try
conn=DBConnection.DBConnect();
String p="MODIFY_"+tableName.toUpperCase()+"("+paramValue+")";
cs=conn.prepareCall( "{call "+p+"}");
cs.execute();
// Suppose to get the result res of the function!!!!
catch (SQLException e)
exceptionMessage="+update"+e.toString();
System.out.println("exceptionMessage="+exceptionMessage);
throw new Exception(exceptionMessage);
finally
Statement stmt=null;
DBConnection.closeConnection(conn,stmt);
return res;
}Obviously I am doing something wrong ..... but I don't know what!!!
Could you help me please?
THanks a lot!Thanks for your quick response.
I need to construct the name of the procedure on the fly because I don't know the name of the table I need to modify until excecution time.
I have modified the code the following way but it still does not work!!!
I still get the exception:
java.lang.Exception: +updatejava.sql.SQLException: Unexpected token CALL, requires SELECT in statement [(call MODIFY_FIELD_SEPARATOR(?)}]
at util.UtilBean.test_upd(UtilBean.java:380)
public String test_upd(String tableName, String paramValue)
throws Exception
String res="0";
Connection conn=null;
CallableStatement cs= null;
try
conn=DBConnection.DBConnect();
cs=conn.prepareCall( "(call MODIFY_"+tableName.toUpperCase()+"(?)}");
cs.setString( 1, paramValue);
cs.execute();
// Suppose to get the result res of the function!!!!
catch (SQLException e)
exceptionMessage="+update"+e.toString();
System.out.println("exceptionMessage="+exceptionMessage);
throw new Exception(exceptionMessage);
finally
Statement stmt=null;
DBConnection.closeConnection(conn,stmt);
return res;
} -
How can I call unix shell script from database using triggers
Hi everyone,
can anybody help me to solve my problem.
we have one table and records are getting inserted into table.
when the record is inserted with 'C',I need to fetch that record-id which is primary key and then by passing that id as an argument I need to execute a shell script which is there in Unix using triggers.
please note DB and Scripts are in different servers.4159efc6-cffb-4496-bd1a-68859f6ce776 wrote:
Hi everyone,
can anybody help me to solve my problem.
we have one table and records are getting inserted into table.
when the record is inserted with 'C',I need to fetch that record-id which is primary key and then by passing that id as an argument I need to execute a shell script which is there in Unix using triggers.
please note DB and Scripts are in different servers.
PL/SQL can only interact with objects on the local DB Server.
PL/SQL can initiate OS local script via any of the following mechanisms: EXTERNAL PROCEDURE, JAVA, DBMS_SCHEDULER
The local script then will need to launch the remote script. -
How can I call a plsql function from an attribute?
I have an attribute defined in an element. I want execute a PLSQL function from the attribute, and display the returne value with an HTML template.
I've defined the attribute's type like PLSQL, and I've put the called of the function in the value of the attribute, but it doesn't work. The only value I obtain is an URL (I think that is the URL of the function or someting like this).
How can I call to my function from the attribute and display the returnes value in the page?
Thanks.Thanks, but it doesn't work. I have an attribute called ID_BOL and I want to associate a sequence to that attribute. I've created a function, with the sequence. This function return de value of the sequence. I want taht the attribute takes the value of the sequenece dinamically.
I've tried it, creating the type attribute like PLSQL, and calling the function from the attribute, but it doesn't work.
How can I return the sequence value to my attribute?
Thanks. -
How can i call mouse click event from keypress event???
How can i call mouse click event from keypress event???
I want same GUI changes to be occured at key press.....i.e . button going down & comming up.....
for calculatorPut all the code that happens on those events into a method. Then call that method from both events.
-
how can i call Apple in usa from Egypt to buy an iPhone from Apple store please who khnow the contacting number answer me
http://www.apple.com/eg/buy/
There are three companies linked to towards the bottom right to purchase an iPhone from. Above those three is Arab Business Machine. Choose one, or check each one out. -
Problem while Calling a CGI pgm From Java with code sample
Hey guys,
I am calling a CGI program from java servlet, while calling cgi program I am passing encoded(Base64) content via post process,
My problem is the encoded data is not posted as expected, the encoded data is corrupting. But when I send encoded data in a text file, cgi program is perfectly decoding and working fine.
Here I am doing Base64 encoding as per requirement, I cannot avoid this encoding.
My doubt is about OutputStreamWriter constructor argument , In OutputStream Constructor I am passing one argument is OutputStream object and another argument is encoding type. I tried with ASCII, US-ASCII & UTF-8 .
My code is as follows, please help me to resolve this issue.
URL url = new URL("CGI server path");
URLConnection urlConnection = url.openConnection();
urlConnection.setDoOutput(true);
OutputStream os = urlConnection.getOutputStream();
BufferedOutputStream buffer = new BufferedOutputStream(os);
OutputStreamWriter writer = new
OutputStreamWriter(buffer, "US-ASCII");
writer.write(encodedPDF-Content);
writer.write("\r\n");
writer.flush();
writer.close();
here encodedPDF-Content is String and it's size is 9565 bytesWhenever you read something in java into string (with Reader implementation) it expects source to contain text in encoding you specified. It then decodes it and makes 16 bit unicode string from it. Whenever you store string using Writers it does reverse operation with specified encoding (may be different than this which you used to read source) and stores text as a sequence of bytes made of 16 bit unicode string. So, passing text back and forth between programs with the help of files or I/O you can make mistake at both reading and writing encoding. Check for it.
Now, when C programm or other application reads file it may take another assumptions about encoding or may even completly ignore it and read source as a binary file. Then, if you have a source text as a file and have to pass it to other application never do it using Reader/Writer. User raw InputStream/OutputStream instead what will preserve all information unchanged.
here encodedPDF-Content is String and it's size is 9565 byteHow id you get this info? String.length() gets you how many chars is in it, it will be half the number of bytes. If you see your input file beeing 9565 bytes long, see my above statements. -
I am calling a CGI program From Java using URL class and I am passing a pdf file under post process. The Content I am appending by Base64 encoding, the CGI program will decode it and print the content
When I send this Content the content is correpting. When CGI program is decoding it is not getting expected content. But the CGI program is working fine If I send that encoded content in a text file.
When I send the encoded content in a text file as attachment OR put in a common drive, the CGI program is working fine. Only I am facing problems when I send this content via post process using URL class.
Why it is happening like this? Is anybody can help me to Resolve this problem?Just a guess: are you sure the content-type header is correct?
-
How can i get the source code from java concurrent program in R12
Hi 2 all,
How can i get the source code from java concurrent program in R12? like , "AP Turnover Report" is java concurrent program, i need to get its source code to know its logic. how can i get its source code not the XML template?
Regards,
Zulqarnainuser570667 wrote:
Hi 2 all,
How can i get the source code from java concurrent program in R12? like , "AP Turnover Report" is java concurrent program, i need to get its source code to know its logic. how can i get its source code not the XML template?
Regards,
ZulqarnainDid you see old threads for similar topic/discussion? -- https://forums.oracle.com/forums/search.jspa?threadID=&q=Java+AND+Concurrent+AND+Source+AND+Code&objID=c3&dateRange=all&userID=&numResults=15&rankBy=10001
Thanks,
Hussein -
How can i call a DLL file from labview?
Iam using a sensoray 2601 module.It is given as DLL file(S2600.DLL).How can i call this function from LabVIEW?
Please Mark the solution as accepted if your problem is solved and donate kudoesAs far as I can tell problems might occur with the call library function node if the the DLL from visual basic is actually an ActiveX dll if that is the case it seems calling the dll by using the Invoke node is the way to go.
Have a look at this
/sletten -
Can i call unix shell script from B2B callout.
Hi,
We had a requirement to invoke a unix shell script from B2B callout implemented class. Here is the code in implementation class:
public void execute(CalloutContext context,List input,List output)
throws CalloutDomainException, CalloutSystemException {
try {
CalloutMessage cmIn = (CalloutMessage)input.get(0);
FileOutputStream fos = null;
String inputFile = "/home/orasoad/digitalsign/input/test.txt";
String outputFile = "/home/orasoad/digitalsign/output/test.txt.gpg";
File outFile = new File(inputFile);
String str =cmIn.getBodyAsString();
fos = new FileOutputStream(outFile);
Writer out = new OutputStreamWriter(fos);
out.write(str);
out.close();
String shellFile = "/home/orasoad/digitalsign/dg.sh";
String cmd[] = new String[] { shellFile, inputFile, outputFile };
Runtime rt = Runtime.getRuntime();
Process pr = rt.exec(cmd);
int i = pr.waitFor();
BufferedReader br = new BufferedReader(new InputStreamReader(pr.getInputStream()));
StringBuffer sb = new StringBuffer();
String line;
while ((line = br.readLine()) != null) {
sb.append(line);
CalloutMessage cmOut = new CalloutMessage(sb.toString());
output.add(cmOut);
} catch (Exception e) {
throw new CalloutDomainException(e);
We were able to execute the unix shell script from standalone java class with same code. But some how it is not working as expected while invoking the B2B java callout.
Is it possible to invoke unix shell script from B2B callout?
Please give inputs.
Regards,Though it's not a good idea to invoke shell scripts from java callout but technically it will work.
But some how it is not working as expected while invoking the B2B java callout.What is not working as expected? Any error in the log (server-diagnostic.log or server.out)?
Regards,
Anuj -
How do I call a C++ program from Java?
I've tried using Runtime.exec to call my C++ program from Java but I don't think I'm doing it correctly. Could someone explain how to properly use it? Here's what I'm trying (this is in an applet that is only going to be running on an intranet so only PCs in my LAN will be affected):
Runtime runtime=runtime.getRuntime();
Process proc =runtime.exec("mkdir C:\\Test");What do you expect your operating system should do with a command "mkdir"? It doesn't understand this. "mkdir" is a shell command, so you need to execute the shell:
runtime.exec("cmd /c mkdir C:\\test");
Maybe you are looking for
-
Document document = builder.parse does not go in correct folder
Hi, In code my directory is set to File directory = new File("C:\\java_training\\com\\XMLtoExcel\\orm\\"); when parsing public void generateExcel(ArrayList<String> array1) throws XPathExpressionException { //System.out.println("in generateexcel " +
-
Satellite A200: How connect a parallel port printer?
Probably a very silly question, but would like to connect A200 series laptop to a parallel port printer that does not have a USB port... what is the best option?
-
F4 search is having an issue in IDES
Hi, There is no documentation available when i am pressing on F4 button. Please try to some body help me. Thanks, RAMANA
-
Every other row (background color)
I want to keep it simple and in css. How can I get this to work properly so every other row has a yellowish background color with no gaps between the words. This is what I have but its producing an odd result. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTM
-
Corporate Templates allowing users to postback through SharePoint rights settings
We currently have our corporate MS Word 2013 templates on SharePoint. We have tested using group policy to set the Workgroup template folder and pull the templates into MS Word templates gallery through SharePoint/OneDrive and it has worked. We are n