Pass javascript array to java
hii
I have to pass a javascript array to my java MyAction.do . So how can i do it???
Thnking You
Being a Java newbie, I can't give you a definitive on how to pass the array to a client-side applet, although it should be possible.
As for passing it to something server-side there are only a couple ways: in a GET request on the query string or in a POST. No matter what, you will have to flatten the array with some method or other, to convert it into a text string that can be parsed on the other end.
I personally favor using hidden form elements and posting the data, because otherwise you have to worry about urlencoding your query string. You could just use javascript itself to write a series of hidden text inputs and then submit the form, so all your form handler has to do is pick up the variables.
Let's say the array is named "myarray":
Code:
+<script language="Javascript">+
document.writeln("<form name=\"myform\" method=\"POST\" action=\"myserver/myhandler.jsp\">")
for(i = 0; i < myarray.length; i+){+
document.writeln("<input type=\"hidden\" name=\"myarray[" i + "]\" value=\"" + myarray[i] + "\">")+
+}+
+document.writeln("</form>")+
+document.myform.submit()+
+</script>+
I know this is clunky and "low-tech" but it will work, and has the benefit of working for any server-side platform that can handle forms
Similar Messages
-
Convert javascript array to java array
Is there any way possible to convert javascript array to java array?
if you will try to experiment a javascript array
putting it to a hidden element, it will be converted
to a string (comma delimited). You can get the value
of that element as a string and use StringTokenizer
class to put the values into a java arrayThanks, got it. -
Example of passing String Array from java to C using JNI
hi all
i searched net for passing string array from java to C but i dont get anything relevent
i have
class stu
int rollno
string name
String [] sub
i want to pass all as String array from java to C and access it C side1. Code it as though it were being passed to another method written in java.
2. Redefine the method implementation to say "native".
3. Run jnih to generate a C ".h" file. You will see that the string array
is passed into C as a jobject, which can be cast to a JNI array.
4. Write the C code to implement the method and meet the interface
in the generated .h file. -
Passing an array from Java to Pl/SQL Procdures
I am relatively new to the Java world and I am unable to pass back an array from Java back to the calling PL/SQL procedure. I have read many of the posts that deal with this issue and in specificly have viewed Ask Tom. My main issue is trying to get the data types matched up. I am able to return varchar2, numbers, and the like, but an array of filenames is not happening. I have tried a variety of "types" but unable to accomplish the task. Please help.
I have my Java class basically defined as:
public static oracle.sql.ARRAY[] getCollection(String directory)
throws SQLException
{ // provide a directory and get a listing of files
File path = new File( directory );
String[] list = path.list();
return list;
SQL Type and PL/SQL Procedure is:
CREATE OR REPLACE TYPE PTO_FILE IS TABLE OF VARCHAR2(100);
create or replace function get_dir_collection( p_directory in varchar2 ) RETURN PTO_FILE
as language java
name 'DirCollection.getCollection( java.lang.String ) return oracle.sql.ARRAY[]';
/I know that it is not an ARRAY. It is however an "array" and I am attempting to map Java's String[][ to some "object" on the oracle side. I have looked at the link you sited and was not able to find the data mapping. I have found that mapping data types between different "languages" is some of the most difficult aspects of working with multiple languages.
Any suggestions? Thanks -
Need help on passing an array to java routine from PL/SQL
I got a math routine in java and the idea is have an array of integer and the java routine does some computatoin and then pass the array back to pl/sql
and I google the web most code is calling pl/sql from java but not the other way round. any help will be really appreciated.
{code}
package tst;
import java.util.*;
public class plsql3 {
private final static int factor1 = 2;
public static void getFib2(int[] in, int[] out, int k){
for (int i=0;i<=k-1;i++){
out[i]= in[i] * factor1;
public static void main(String[] arg){
int[] in2 = {1,2,3,4,5};
int[] out2= {0,0,0,0,0};
getFib2(in2,out2,2);
for ( int j = 0 ; j <= out2.length-1;j++) {
System.out.println(out2[j]);
{code}
{code}
CREATE or replace PROCEDURE getfib5 (x IN OUT numlist, y IN OUT numlist, k in number)
AS LANGUAGE JAVA
NAME 'tst.plsql3.getFib2(int[], int[],int)';
set serveroutput on format wraped;
declare
in2 numlist := numlist(1,2,3,4,5,6);
out2 numlist := numlist(0,0,0,0,0,0);
begin
--in2(0) := 1;
--in2(1) := 2;
--in2(2) := 3 ;
for i in 1..in2.count
loop
dbms_output.put_line(in2(i));
end loop;
for i in 1..in2.count
loop
dbms_output.put_line(out2(i));
end loop;
getFib5(in2,out2,2);
for i in 1..in2.count
loop
dbms_output.put_line(in2(i));
end loop;
for i in 1..in2.count
loop
dbms_output.put_line(out2(i));
end loop;
--dbms_output.put_line(in2.count);
end;
{code}
{code}
javac -source 1.5 -target 1.5 tst/plsql3.java
{code}
Error report:
ORA-00932: inconsistent datatypes: expected a value at argument position 1 that is convertible to a Java int got an Oracle named TYPE (ADT, REF etc)
ORA-06512: at "TK1.GETFIB5", line 1
ORA-06512: at line 18
00932. 00000 - "inconsistent datatypes: expected %s got %s"
*Cause:
*Action:http://asktom.oracle.com/pls/asktom/f?p=100:11:::::P11_QUESTION_ID:3696816290928
-
How to Pass String array from Java to PL/SQL and this use in CURSOR
hi,
I cant understand how to pass Array String as Input Parameter to the Procedure and this array use in Cursor for where condition like where SYMPTOM in( ** Array String **).
This array containing like (SYMPTOM ) to be returned from the java to the
pl/sql (I am not querying the database to retrieve the information).
I cannot find an example on this. I will give the PL/SQL block
create or replace procedure DISEASE_DTL<*** String Array ***> as
v_SYMPTOM number(5);
CURSOR C1 is
select distinct a.DISEASE_NAME from SYMPTOM_DISEASE_RD a
where ltrim(rtrim(a.SYMPTOM)) in ('Fever','COUGH','Headache','Rash') ------- ***** Here use this array element(like n1,n2,n3,n4,n5..) ******
group by a.DISEASE_NAME having count(a.DISEASE_NAME) > 3 ----------- ***** 3 is no of array element - 1 (i.e( n - 1))*****
order by a.DISEASE_NAME ;
begin
for C1rec IN C1 loop
select count(distinct(A.SYMPTOM)) into v_SYMPTOM from SYMPTOM_DISEASE_RD a where A.DISEASE_NAME = C1rec.DISEASE_NAME;
insert into TEMP_DISEASE_DTLS_SYMPTOM_RD
values (SL_ID_SEQ.nextval,
C1rec.DISEASE_NAME,
(4/v_SYMPTOM), --------**** 4 is no of array element (n)************
(1-(4/v_SYMPTOM)));
end loop;
commit;
end DISEASE_DTL;
Please give the proper solution and step ..
Thanking you,
AsishI've haven't properly read through your code but here's an artificial example based on a sql collection of object types - you don't need that, you just need a type table of varchar2 rather than a type table of oracle object type:
http://orastory.wordpress.com/2007/05/01/upscaling-your-jdbc-app/ -
Passing String Array from Java to PL/SQL
Hi,
We are having couple of packages which have been written in PL/SQL . I would like to know how i can send arrays as input parameters from Java to any stored proc in Oracle. I am having Oracle 8i as the DB and am using Websphere RSA for deployment purposes.
please find below Java , PL/SQL code and exception
PL/SQL Code :
PACKAGE PKG_SURCHARGE
IS
TYPE commodity_key IS TABLE OF VARCHAR2(500) INDEX BY BINARY_INTEGER;
PROCEDURE RETRIEVE_CHARGES
in_Commodity_tab IN commodity_key,
IS
BEGIN
dbms_output.put_line('in_Commodity_tab(' || '0' || ') : ' || in_Commodity_tab(0) );
Java Code :
CallableStatement cstmt=null;
Connection conn=null;
try{
conn=getConnection();
System.out.println("++++++connected");
String sqlStr = "{call Pkg_Surcharge.RETRIEVE_CHARGES(?) }";
cstmt = conn.prepareCall(sqlStr );
//1.
String[] javaArray={"20081117","20081117"};
ArrayDescriptor dateDescripter = ArrayDescriptor.createDescriptor( "commodity_key", conn );
oracle.sql.ARRAY dateArray = new oracle.sql.ARRAY(dateDescripter, conn, javaArray);
System.out.println("++++++registered-1");
Catch (Exception e){
e.printStackTrace();
Exception Occured:
java.sql.SQLException: Invalid Pattern Name <Schema Name>.commodity_key
Appreciate your help in this regard
Thanks
Srini
Edited by: [email protected] on Nov 25, 2008 4:55 AMAvi is correct. You must create a varray or nested table instead of using a PL/SQL index-by table.
SQL> create type commodity_key as varray(#) of varchar2(500);
or
SQL> create type commodity_key as table of varchar2(500);
Use the varray if you know the number of items in the array. Otherwise, use the nested table. -
I am doing a simple java Servlet example...
I have value that is assigned in a one of the javascript function().
Below i have the function where i get the columnValue....
i want to use that value in the doPost method in my Servlet1 class...
Can someone please tell me how i can do this...
function getGridValue(oColumn) {
var oRow;
var oCell;
var lIdx;
var columnValue;
try {
lArrayLength = GridArrays.length;
if (lArrayLength < 1) {
return false;
for (lLoop=0; lLoop<lArrayLength; lLoop++) {
oRow = GridArrays[lLoop];
oCell = oRow[0];
columnValue = oRow[oColumn];
if (oCell.SortVal == 1) {
alert(columnValue.SortVal);
break;
return true;
catch(exception){
if(exception.description == null){
alert("GridSerVal: " + exception.message);
else{
alert("GridSetVal: " + exception.description);
Servlet1 class
public void doPost(HttpServletRequest request, HttpServletResponse res)
throws IOException, ServletException
String xParameterName = null;
String xParameterValue = null;
PrintWriter out = res.getWriter();
PolicyInformation policyInformation = null;
Enumeration e = request.getParameterNames();
while (e.hasMoreElements()) {
xParameterName = (String) e.nextElement();
xParameterValue = request.getParameter(xParameterName);
if ((xParameterValue.trim().length() !=0 )){
if(xParameterName.compareTo("firstnameTextfield")==0){
else if(xParameterName.compareTo("lastnameTextfield")==0){
else if(xParameterName.compareTo("policynumberTextfield")==0){
StringBuffer outstring = new StringBuffer();
outstring.append(createScript.policyReCreateSearchForm(xParameterValue));
outstring.append(createScript.setTopPart());
outstring.append(createScript.getHeader());
Vector policyInformationVector1 = getPolicyInformation(res, xParameterValue);
Iterator iter = policyInformationVector1.iterator();
PolicyInformation aPolicyInformation = null;
while(iter.hasNext()){
Object[] data = new String[policyInformationVector1.size()];
for (int ii=0; ii < data.length; ii++){
int rowNum = ii + 1;
aPolicyInformation = (PolicyInformation) iter.next();
f = aPolicyInformation.getFirstName();
l = aPolicyInformation.getLastName();
d = aPolicyInformation.getDOB();
s = aPolicyInformation.getSSN();
p = aPolicyInformation.getPolicyNumber();
m = aPolicyInformation.getMiddleName();
pid = aPolicyInformation.getPid();
outstring.append(createScript.setRowValue(f,m,l,p,pid,d,s,rowNum));
outstring.append(createScript.setRowValue1());
outstring.append(createScript.getBottom());
out.println(outstring.toString());
else if(xParameterName.compareTo("ssnTextfield")==0){
THis is where i want to get the value from the javascript and use that value to run a query...
// checks if the ViewSubmitButton is submitted....
if(xParameterName.compareTo("viewSubmitButton") == 0){
} // end of while(e.hasMoreElements())I'm not quite sure what your problem is specifically, but at first glance I can tell you that you can't access the response object until you are done with your request object. Make sure you do everything you want to do with the request object and then when you are done make your call to res.getWriter() and send your output.
-
Passing javascript variable to java bean
Hi all,
Is there any way to pass a java script variable to a java bean. i'm trying hard but in vain. please suggest a way how to do it...The variable u want to pass declare that in a dataobject class i.e consisting of getter and setters ...... when you will use the jsp:useBean tab and the setProperty tag along with the class name it will set the value of the variables ...... use form method = get to set the variables.
-
Pass 2D array from java to PLSQL
HI,
My requirement is that I have to pass dynamic parameters to be stored in a table. The table I have is
CODE || TAG_LABEL || TAG_COLMN_NAME
023 || Registration || CHAR_TAG1
023 || Agreement Number || NUM_TAG1
023 || Agency || NUM_TAG2
023 || Start Date || DATE_TAG1
this table A. gives me the list of all possible parametes
CODE || CHAR_TAG1 || CHAR_TAG2 || NUM_TAG1 || NUM_TAG2 .. ..
023 || 420/09 || -- || 100023 || 1002
021 || -- || 400030 || -- || --
023 || 450/10 || -- || 100025 || --
this table B gives the place where the values for this parameter has to be stored.So for code 023 if I have parameters say Registration='240/10' and start_date = '10/02/2010' then, how do I pass these dynamic paramters to the plsql and from there how do i handle storing this in my final Table B.
I searched the net for Dynamic sql and I am very basic in PLSQLs. Can anyone please help or atleast if there is a documentation that does exactly this, it would be very helpful.
Thanks
RacheFrom the pl/sql side you need to create your object types
create or replace type sample_array_obj
as object( firstitem varchar2(20 char),
seconditem varchar2(10 char)
create or replace
type sample_array_type is table of sample_array_objand then you need to grant execute access on both the object and type
grant execute on sample_array_obj to public;
grant execute on sample_array_type to public;you have to declare these to java then. (I'm not a java programmer, but the java then has to get its collection type from the database) -
How to pass int array as an IN parameter to PLSQL Procedure
Hi,
How to pass int array in java to a stored procedure througn jdbc
and what type of data type I should declare to this IN parameter
in PLSQL Procedure.
Thanks,
SimiHi,
The best way to do what you want depends on what you want. Start by describing what you need to do. It's best to post some sample data (CREATE TABLE and INSERT statments) and what results you want from that sample data. (See the forum FAQ: https://forums.oracle.com/message/9362002)
If you have ideas about how to do the job (e.g., populating a temporary table) it can be helpful to include those, too, but distinguish clearly between WHAT you need to do and HOW you might do it.
As Bencol suggested, a SYS_REFCURSOR might be the best way to pass back the results.
Since you didn't post your table, or even describe what you wanted to do with it, I'll illustrate using scott.emp, which is probably on your system.
Say you wanted a procedure that took a DATE as an argument, and returned a some designated columns (empno, ename and hiredate in the example below) for all employees hired on or after the given DATE. You might write a procedure like this:
CREATE OR REPLACE PROCEDURE hired_since
( start_date IN DATE
, out_data OUT SYS_REFCURSOR
AS
BEGIN
OPEN out_data FOR
SELECT empno, ename, hiredate
FROM scott.emp
WHERE hiredate >= start_date;
END hired_since;
SHOW ERRORS
You can test it in SQL*Plus like this:
VARIABLE c REFCURSOR
EXEC hired_since (DATE '1982-01-01', :c);
PRINT :c
The output I got from this test was:
EMPNO ENAME HIREDATE
7788 SCOTT 19-APR-87
7876 ADAMS 23-MAY-87
7934 MILLER 23-JAN-82 -
How to pass java arraylist into javascript arrays
Hi, i have declare an arraylist
ArrayList list1 = new ArrayList();Inside the arraylist, there are elements. Now, i wan to pass the elements in the java arraylist into javascript arrays but i encounter javascript errors.
This is how i code.
var arr1 = new Array();
<%
for ( int x =0; x<list1.size(); x++)
%>
arr1[<%=x%>] = <%=(String)list1.get(x)%>;
<%
%>how do i solve this problem?
Thanks for the guidance in advanceJTech wrote:
Hi,
Use Quotes around string value ( arr1[indexposition] = "stringvalue";), when assign to javascript array as below.
arr1[<%=x%>] = "<%=(String)list1.get(x)%>"; Regards,
Ram.Hi Ram,
How about using arr1 = <%=list.toArray()%> ??? Is this possible? I tried it but was not working on my IDE. Do you have any solutions for this??
Regards,
Thiagu -
How to pass an array which in the jsp to a javascript file
now i have 2 files: jsp and js(javascript)
i want pass an array which in the jsp to another file--> js file
how can i do it ???
can u give me some related links or some source codes as the references???
thxbcos ....my senior has resigned!!! so i take over his job !!!!!
depend on the talent and the project ....only that way to implement to whole project !!!!
but , i had settled it already ....
it is very simple
in the middle.jsp
Collection result = menuManager.getUserRoleMenu(webSessionUser.getGnuserId());
String menuname[]=new String[110];
int menucounter=0;
Iterator vi = result.iterator();
while(vi.hasNext())
HashMap hm=(HashMap)vi.next();
menuname[menucounter]=hm.toString();
menucounter++;
int i;
String tempstr="";
for(i=0;i<menuname.length;i++)
tempstr+=menuname[i]+",";
session.setAttribute("menuname",tempstr);
%>
<script language="javascript">
menu123("<%=tempstr %>");
</script>
in the body,js
function menu123(string123)
//doing
so ....through the script --menu123
i can get the string from jsp to the js!!!!!
is it very simple, but it spends my 2 days!!!
i just learn javascript ....about 1 month !!! -
How to pass Array of Java objects to Callable statement
Hi ,
I need to know how can I pass an array of objects to PL/SQL stored procedure using callable statement.
So I am having and array list of some object say xyz which has two attributes string and double type.
Now I need to pass this to a PL/SQL Procedure as IN parameter.
Now I have gone through some documentation for the same and found that we can use ArrayDescriptor tp create array (java.sql.ARRAY).
And we will use a record type from SQL to map this to our array of java objects.
So my question is how this mapping of java object's two attribute will be done to the TYPE in SQL? can we also pass this array as a package Table?
Please help
ThanksI seem to remember that that is in one of Oracle's online sample programs.
http://www.oracle.com/technology/sample_code/tech/java/sqlj_jdbc/index.html -
Pass an array of a user defined class to a stored procedure in java
Hi All,
I am trying to pass an array of a user defined class as an input parameter to a stored procedure. So far i have done the following:
Step 1: created an object type.
CREATE TYPE department_type AS OBJECT (
DNO NUMBER (10),
NAME VARCHAR2 (50),
LOCATION VARCHAR2 (50)
Step 2: created a varray of the above type.
CREATE TYPE dept_array1 AS TABLE OF department_type;
Step 3:Created a package to insert the records.
CREATE OR REPLACE PACKAGE objecttype
AS
PROCEDURE insert_object (d dept_array);
END objecttype;
CREATE OR REPLACE PACKAGE BODY objecttype
AS
PROCEDURE insert_object (d dept_array)
AS
BEGIN
FOR i IN d.FIRST .. d.LAST
LOOP
INSERT INTO department
VALUES (d (i).dno,d (i).name,d (i).location);
END LOOP;
END insert_object;
END objecttype;
Step 4:Created a java class to map the columns of the object type.
public class Department
private double DNO;
private String Name;
private String Loation;
public void setDNO(double DNO)
this.DNO = DNO;
public double getDNO()
return DNO;
public void setName(String Name)
this.Name = Name;
public String getName()
return Name;
public void setLoation(String Loation)
this.Loation = Loation;
public String getLoation()
return Loation;
Step 5: created a method to call the stored procedure.
public static void main(String arg[]){
try{
Department d1 = new Department();
d1.setDNO(1); d1.setName("Accounts"); d1.setLoation("LHR");
Department d2 = new Department();
d2.setDNO(2); d2.setName("HR"); d2.setLoation("ISB");
Department[] deptArray = {d1,d2};
OracleCallableStatement callStatement = null;
DBConnection dbConnection= DBConnection.getInstance();
Connection cn = dbConnection.getDBConnection(false); //using a framework to get connections
ArrayDescriptor arrayDept = ArrayDescriptor.createDescriptor("DEPT_ARRAY", cn);
ARRAY deptArrayObject = new ARRAY(arrayDept, cn, deptArray); //I get an SQLException here
callStatement = (OracleCallableStatement)cn.prepareCall("{call objecttype.insert_object(?)}");
((OracleCallableStatement)callStatement).setArray(1, deptArrayObject);
callStatement.executeUpdate();
cn.commit();
catch(Exception e){
System.out.println(e.toString());
I get the following exception:
java.sql.SQLException: Fail to convert to internal representation
My question is can I pass an array to a stored procedure like this and if so please help me reslove the exception.
Thank you in advance.OK I am back again and seems like talking to myself. Anyways i had a talk with one of the java developers in my team and he said that making an array of structs is not much use to them as they already have a java bean/VO class defined and they want to send an array of its objects to the database not structs so I made the following changes to their java class. (Again hoping some one will find this useful).
Setp1: I implemented the SQLData interface on the department VO class.
import java.sql.SQLData;
import java.sql.SQLOutput;
import java.sql.SQLInput;
import java.sql.SQLException;
public class Department implements SQLData
private double DNO;
private String Name;
private String Location;
public void setDNO(double DNO)
this.DNO = DNO;
public double getDNO()
return DNO;
public void setName(String Name)
this.Name = Name;
public String getName()
return Name;
public void setLocation(String Location)
this.Location = Location;
public String getLoation()
return Location;
public void readSQL(SQLInput stream, String typeName)throws SQLException
public void writeSQL(SQLOutput stream)throws SQLException
stream.writeDouble(this.DNO);
stream.writeString(this.Name);
stream.writeString(this.Location);
public String getSQLTypeName() throws SQLException
return "DOCCOMPLY.DEPARTMENT_TYPE";
Step 2: I made the following changes to the main method.
public static void main(String arg[]){
try{
Department d1 = new Department();
d1.setDNO(1);
d1.setName("CPM");
d1.setLocation("LHR");
Department d2 = new Department();
d2.setDNO(2);
d2.setName("Admin");
d2.setLocation("ISB");
Department[] deptArray = {d1,d2};
OracleCallableStatement callStatement = null;
DBConnection dbConnection= DBConnection.getInstance();
Connection cn = dbConnection.getDBConnection(false);
ArrayDescriptor arrayDept = ArrayDescriptor.createDescriptor("DEPT_ARRAY", cn);
ARRAY deptArrayObject = new ARRAY(arrayDept, cn, deptArray);
callStatement = (OracleCallableStatement)cn.prepareCall("{call objecttype.insert_array_object(?)}");
((OracleCallableStatement)callStatement).setArray(1, deptArrayObject);
callStatement.executeUpdate();
cn.commit();
catch(Exception e){
System.out.println(e.toString());
and it started working no more SQLException. (The changes to the department class were done manfully but they tell me JPublisher would have been better).
Regards,
Shiraz
Maybe you are looking for
-
Import Format for Separte Debit and Credit Columns (comma delimited file)
I have a file that is comma delimited with a sparate debit column and a separate credit column: Sample: Ent,Acct,description,Dr,Cr ,1000,test,100, ,110010,another test,,100 My import format is this: Comma delimited Field Number Number of Fields Expre
-
All right. I have 2 (maybe 3) iTunes folder layouts in my Music DIR. I have clicked keep it organized and copy into... iTunes Album Artwork iTunes Media Artists - and album and songs subfolders <-- Audio Books
-
Adjusting portal theme of Web Dynpro ABAP application
Hi, can the style of all UI elements in our Web Dynpro ABAP application changed in the style sheet editor of the portal? Or shall we avoid some already in the application? And can we also use the Eclipse Portal Editor to change the theme for our ABAP
-
Does n e 1 read these things?????? I need help reeeelly bad
Before my music on itunes kept getting all grayed out, so i got some help and turned on manually somthing, but now my ipod always says do not disconect! also, I just bought a song and it won't appear on my ipod, just my library. can n e 1 help? I hav
-
How do I delete this album???
I have an album stuck on my iPhone and I can't figure out how to delete it! The songs cannot be deleted when I try to swipe them to the left, and I can't get rid of this annoying album :/ Please help me!!