473,385 Members | 1,523 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Problem in getting attributes from webservice to servlet when d return type String[]

13
I made a Webservice Operation whose return type is STRING [] Following is the code

Expand|Select|Wrap|Line Numbers
  1. @WebMethod(operationName = "authorize") public String [] authorize(@WebParam(name = "Username") String Username) 
  2.   CAuthorization CA = new CAuthorization(); 
  3.   String [] Result= null; 
  4.   try {
  5.     Result = CA.CheckAuthorization(Username); 
  6.   } catch (SQLException ex) {
  7.     Logger.getLogger(WS_Authentication.class.getName()).log(Level.SEVERE, null, ex); 
  8.   }
  9.   return Result;
  10. }
And then i made a Servlet The code of the servlet thing is :
Expand|Select|Wrap|Line Numbers
  1. try { // Call Web Service Operation
  2.   java.lang.String result = null;
  3.   result =  port.authorize(Username);
  4.   out.println("Result = "+result);
  5. } catch (Exception ex) {
  6.   // TODO handle custom exceptions here
  7. }
Problem is in my WEbservice Code in RETURN STATEMENT i have attributes of any table and i want to take these attributes to servlet so that i can see them on my front end but what im getting here is the only the LAST ATTRIBUTE

I WANT TO HAVE ALL THE ATTRIBUTES HERE ; so that i can print them in my front end

HELP!
Dec 9 '09 #1

✓ answered by Sundhas

This is the way u can handle Webservice Operation of String Return type

@WebMethod(operationName = "authorize")
public String authorize(@WebParam(name = "Username")
String Username) {

CAuthorization CA = new CAuthorization();
StringBuffer result = new StringBuffer();
try {
if (CA.CheckAuthorization(Username).length > 0) {
result.append(CA.CheckAuthorization(Username)[0]);
for (int i = 1; i < CA.CheckAuthorization(Username).length; i++) {
result.append(",");
result.append(CA.CheckAuthorization(Username)[i]);
}
}
} catch (SQLException ex) {
Logger.getLogger(WS_Authentication.class.getName() ).log(Level.SEVERE, null, ex);
}
//TODO write your implementation code here:
return result.toString();
}

8 3111
chaarmann
785 Expert 512MB
The authorize-method interface is defined to pass an array of strings (all attributes) back, but you are only assigning a single String (one attribute) for the return value.
"... public String [] authorize(..." --> "..String result = port.authorize(..."

Solution:
"..String[] resultArray = port.authorize(..."

Please be so kind and don't shout in your answer, my ears are still ringing and my eyes are tingling. There is a (B)old-button on the top, please use it.
Dec 9 '09 #2
Sundhas
13
Hey thanks for the reply
i tried this too what u sugested already but actually it doen't let me it says " That Result is STRING [] and port.authorize (... is SIMPLE string...

any other way to do it in your mind?

what i did i converted STRING [] into string separated with ", " in webservices so that i can get the attributes on servlet... But its not the cool way i want to know how do we get STRING [] in servlet..
Dec 9 '09 #3
chaarmann
785 Expert 512MB
Sorry, I don't know much about webservices, but can you return other objects than simple strings?
If yes then you can try with Vector() or ArrayList()
Dec 9 '09 #4
Sundhas
13
Right! Yes we can use ArrayList ( )
Thankyou :)
Dec 9 '09 #5
Hi Sundhas,

Did u solve the problem.
Give you give some example how u finally did it?

Please help!!

Thnx
Mar 28 '10 #6
Sundhas
13
This is the way u can handle Webservice Operation of String Return type

@WebMethod(operationName = "authorize")
public String authorize(@WebParam(name = "Username")
String Username) {

CAuthorization CA = new CAuthorization();
StringBuffer result = new StringBuffer();
try {
if (CA.CheckAuthorization(Username).length > 0) {
result.append(CA.CheckAuthorization(Username)[0]);
for (int i = 1; i < CA.CheckAuthorization(Username).length; i++) {
result.append(",");
result.append(CA.CheckAuthorization(Username)[i]);
}
}
} catch (SQLException ex) {
Logger.getLogger(WS_Authentication.class.getName() ).log(Level.SEVERE, null, ex);
}
//TODO write your implementation code here:
return result.toString();
}
Mar 28 '10 #7
Thanks for reply. Basically i wanted to query database and send the multiple rows to client. Java web service should return multiple rows and columns.
Mar 29 '10 #8
Sundhas
13
Yes.. Previously i was trying to do so but somehow wasnt able to.. So i figured this out.
Sorry can't help more

Regards
Sundhas
Mar 29 '10 #9

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Johnnie | last post by:
Hello, I am trying to submit a request object to a server (not local), using a servlet. When given a ZIP code this particular server is supposed to return xml with the city/state/areacode etc......
1
by: citnamor | last post by:
Hello, I'm trying to access a webservice which runs on our SOAP Server (Apache Tomcat) with Windows 2000 Advanced Server. I simply added the webreference local copy of wsdl file into dotNet...
16
by: Dany | last post by:
Our web service was working fine until we installed .net Framework 1.1 service pack 1. Uninstalling SP1 is not an option because our largest customer says service packs marked as "critical" by...
5
by: Stacey Levine | last post by:
I have a webservice that I wanted to return an ArrayList..Well the service compiles and runs when I have the output defined as ArrayList, but the WSDL defines the output as an Object so I was...
1
by: louis_la_brocante | last post by:
Dear all, I am having trouble generating a client proxy for a webservice whose methods return a "complex" type. The type is complex in that it is a class whose members are a mix of primitive...
0
by: TraceyAnnison | last post by:
I wonder if you can help me - I'm new to this, and working in a project that has already been configured to work with Axis. We have a Java project built with the Spring framework, in order to...
3
by: JMcCrillis | last post by:
I've implemented a FileUpload servlet using AJAX and JS. It appears to be working well but for one issue. I used XMLHTTP so I could intercept the response in Javascript and write it out to a field...
2
by: dmstn | last post by:
Hey! I've got a little problem. I have to make a web site for a university essay. I curently have to create a search engine. Users can enter a hotel name in a search bar and results have to appear in...
2
raveendrabikkina
by: raveendrabikkina | last post by:
03/17 15:45:40 error Error creating form bean of class epost.form.BpUploadForm java.lang.InstantiationException: epost.form.BpUploadForm at java.lang.Class.newInstance0(Class.java:291) ...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.