Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

consuming web service from xhtml file

 
prats evik
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
can anyone tell me how can we consume a web service from a xhtml file?
here is my code

<?xml version="1.0" encoding="UTF-8"?>
<!--
To change this template, choose Tools | Templates
and open the template in the editor.
-->
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:h="http://java.sun.com/jsf/html">
<head>
<title>Cost</title>
</head>
<body>
Zip code: <h:inputText id="zip" required="true"/><br />
Weight: <h:inputText id="weight" required="true"/><br />
Cost:<hutputText id="cost" required="true" value=""/><br/>


<h:commandButton value="Submit" action="#{productBean.calculate()}"/>

</body>
</html>




/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package test;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import javax.annotation.Resource;
import javax.jws.WebService;
import javax.jws.WebMethod;
import javax.jws.WebParam;
import javax.sql.DataSource;
import javax.sql.rowset.CachedRowSet;////not working

/**
*
* @author pratik khivesara
*/
@WebService(serviceName = "NewWebService2")
public class NewWebService2 {
@Resource(name="jdbc/addressbook")

DataSource dataSource;
int weight;
int cost;
int zip;

/** This is a sample web service operation */
@WebMethod(operationName = "hello")

public String hello1(@WebParam(name = "zip") int txt,@WebParam(name = "weight") int txt2){
String result = "empty result";
try{
if (dataSource == null) {
result = "a";
throw new SQLException("Unable to obtain DataSource"); // checking whether the database is injected
}



Connection connection = dataSource.getConnection();//obtain a connectio

if (connection == null) {
throw new SQLException("Unable to connect to DataSource");//checking whether the connection is established
}
int cost=(txt+txt2)/12;
result=Integer.toString(cost);


}catch(Exception e){}
return result;

}
}

thanks!!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic