473,406 Members | 2,343 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,406 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 3114
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) ...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.