wood burning stoves 2.0*
The moose likes Web Services and the fly likes consuming web service from xhtml file Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Web Services
Bookmark "consuming web service from xhtml file" Watch "consuming web service from xhtml file" New topic
Author

consuming web service from xhtml file

prats evik
Greenhorn

Joined: Apr 04, 2012
Posts: 6
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!!
 
wood burning stoves
 
subject: consuming web service from xhtml file
 
Similar Threads
Target Unreachable, identifier resolved to null (JSF 2.0)
Displaying 2D array using data tables
database help
Bug in chrome
Target Unreachable