Posts Tagged ‘java’

I can provide two ways,

a.jsp:

<html>
<script language="javascript" type="text/javascript">
function call(){
var name = "xyz";
window.location.replace("a.jsp?name="+name);
}
</script>
<input type="button" value="Get" onclick='call()'>
<%
String name=request.getParameter("name");
if(name!=null){
out.println(name);
}
%>
</html>

2)b.jsp:

<script>
var v="xyz";
</script>
<% String st="<script>document.writeln(v)</script>";
out.println("value="+st); %>

  

import java.sql.CallableStatement;

import java.sql.Connection;

import java.sql.DriverManager;

public class Main {

  public static void main(String[] argsthrows Exception {

    Connection conn = getOracleConnection();

    // Step-2: identify the stored procedure

    String proc3StoredProcedure = “{ call proc3(?, ?, ?) }”;

    // Step-3: prepare the callable statement

    CallableStatement cs = conn.prepareCall(proc3StoredProcedure);

    // Step-4: set input parameters …

    // first input argument

    cs.setString(1“abcd”);

    // third input argument

    cs.setInt(310);

    // Step-5: register output parameters …

    cs.registerOutParameter(2, java.sql.Types.VARCHAR);

    cs.registerOutParameter(3, java.sql.Types.INTEGER);

    // Step-6: execute the stored procedures: proc3

    cs.execute();

    // Step-7: extract the output parameters

    // get parameter 2 as output

    String param2 = cs.getString(2);

    // get parameter 3 as output

    int param3 = cs.getInt(3);

    System.out.println(“param2=” + param2);

    System.out.println(“param3=” + param3);

    conn.close();

  }

  private static Connection getHSQLConnection() throws Exception {

    Class.forName(“org.hsqldb.jdbcDriver”);

    System.out.println(“Driver Loaded.”);

    String url = “jdbc:hsqldb:data/tutorial”;

    return DriverManager.getConnection(url, “sa”“”);

  }

  public static Connection getMySqlConnection() throws Exception {

    String driver = “org.gjt.mm.mysql.Driver”;

    String url = “jdbc:mysql://localhost/demo2s”;

    String username = “oost”;

    String password = “oost”;

    Class.forName(driver);

    Connection conn = DriverManager.getConnection(url, username, password);

    return conn;

  }

  public static Connection getOracleConnection() throws Exception {

    String driver = “oracle.jdbc.driver.OracleDriver”;

    String url = “jdbc:oracle:thin:@localhost:1521:caspian”;

    String username = “mp”;

    String password = “mp2”;

    Class.forName(driver)// load Oracle driver

    Connection conn = DriverManager.getConnection(url, username, password);

    return conn;

  }

}

           

         

    

  

CallStoresProcedureInOracleAndPassInOutParameters.zip( 3,849 k)

Conversion PDF to Byte and Vice verse

Posted: January 13, 2012 in Random Posts
Tags: , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , ,

Simple conversion easily enjoy the word of JAVA……………….

public static byte[] convertPDFToByteArray(String sourcePath) {
byte[] bytes=null;
InputStream inputStream;

File file = new File(sourcePath);

try {
inputStream = new FileInputStream(file);
bytes = new byte[(int)file.length()];
int read = inputStream.read(bytes);
} catch (IOException ex) {
Logger.getLogger(

DesktopApplication3View.class.getName()).log(Level.SEVERE, null, ex);
}return bytes;

}

public void convertByteArrayToPDF(String sourcePath,byte[] bytes) {
OutputStream out;
try {
out = new FileOutputStream(sourcePath);
try {
out.write(bytes);
out.close();
} catch (IOException ex) {
Logger.getLogger(DesktopApplication3View.class.getName()).log(Level.SEVERE, null, ex);
}
} catch (FileNotFoundException ex) {
Logger.getLogger(DesktopApplication3View.class.getName()).log(Level.SEVERE, null, ex);
}

}

Web Services – Web Services Tutorials

Posted: January 12, 2012 in Random Posts
Tags: , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , ,

In this section of the Web Services tutorial you will be familiarized with the Web Services.

Introduction

The next generation of distributed computing has arrived. A Web service is a unit of managed code that can be remotely invoked using HTTP, that is, it can be activated using HTTP requests.

Historically speaking, remote access to binary units required platform-specific and sometimes language-specific protocols. For example, DCOM clients access remote COM types using tightly coupled RPC calls. CORBA requires the use of tightly coupled protocol referred to as Internet Inter-ORB Protocol (IIOP), to activate remote types. Enterprise JavaBeans (EJBs) requires a Remote Method Invocation (RMI) Protocol and by and large a specific language (Java). Thus each of these remote invocation architectures needs proprietary protocols, which typically require a tight connection to the remote source.

One can access Web services using nothing but HTTP. Of all the protocols in existence today, HTTP is the one specific wire protocol that all platforms tend to agree on. Thus , using Web services, a Web service developer can use any language he wish and a Web service consumer can use standard HTTP to invoke methods a Web service provides. The bottom line is that we have true language and platform integration . Simple Object Access Protocol (SOAP) and XML are also two key pieces of the Web services architecture.

What is a Web Service

Web services constitute a distributed computer architecture made up of many different computers trying to communicate over the network to form one system. They consist of a set of standards that allow developers to implement distributed applications – using radically different tools provided by many different vendors – to create applications that use a combination of software modules called from systems in disparate departments or from other companies.

A Web service contains some number of classes, interfaces, enumerations and structures that provide black box functionality to remote clients. Web services typically define business objects that execute a unit of work (e.g., perform a calculation, read a data source, etc.) for the consumer and wait for the next request. Web service consumer does not necessarily need to be a browser-based client. Console-baed and Windows Forms-based clients can consume a Web service. In each case, the client indirectly interacts with the Web service through an intervening proxy. The proxy looks and feels like the real remote type and exposes the same set of methods. Under the hood, the proxy code really forwards the request to the Web service using standard HTTP or optionally SOAP messages.

Web Service Standards

Web services are registered and announced using the following services and protocols. Many of these and other standards are being worked out by the UDDI project, a group of industry leaders that is spearheading the early creation and design efforts.

Universal Description, Discovery, and Integration (UDDI) is a protocol for describing available Web services components. This standard allows businesses to register with an Internet directory that will help them advertise their services, so companies can find one another and conduct transactions over the Web. This registration and lookup task is done using XML and HTTP(S)-based mechanisms.

Simple Object Access Protocol (SOAP) is a protocol for initiating conversations with a UDDI Service. SOAP makes object access simple by allowing applications to invoke object methods or functions, residing on remote servers. A SOAP application creates a request block in XML, supplying the data needed by the remote method as well as the location of the remote object itself.

Web Service Description Language (WSDL), the proposed standard for how a Web service is described, is an XML-based service IDL (Interface Definitition Language) that defines the service interface and its implementation characteristics. WSDL is referenced by UDDI entries and describes the SOAP messages that define a particular Web service.

ebXML (e-business XML) defines core components, business processes, registry and repository, messaging services, trading partner agreements, and security.

Implementing Web Services

Here comes a brief step-by-step on how a Web service is implemented.

  • A service provider creates a Web service
  • The service provider uses WSDL to describe the service to a UDDI registry
  • The service provider registers the service in a UDDI registry and/or ebXML registry/repository.
  • Another service or consumer locates and requests the registered service by querying UDDI and/or ebXML registries.
  • The requesting service or user writes an application to bind the registered service using SOAP in the case of UDDI and/or ebXML
  • Data and messages are exchanged as XML over HTTP

Web Service Infrastructure

Even though Web services are being built using existing infrastructure, there exists a strong necessity for a number of innovative infrastructures. The core architectural foundation of Web services are XML, XML namespaces, and XML schema. UDDI, SOAP, WSDL, ebXML and security standards are being developed in parallel by different vendors

Web Services Technologies and Tools

There are a number of mechanisms for constructing Web services. Microsoft has come out with a new object-oriented language C# as the development language for Web services and .NET framework. Microsoft has an exciting tool called Visual Studio .NET in this regard. The back end database can be Microsoft SQL Server 2000 in Windows 2000 Professional.

Sun Microsystems has its own set of technologies and tools for facilitating Web services development. Java Servlets, Java Server Pages (JSPs), Enterprise JavaBeans (EJB) architecture and other Java 2 Enterprise Edition (J2EE) technologies play a very critical role in developing Web services.

There are a number of tools for developing Web services. They are Forte Java IDE, Oracle JDeveloper, and WebGain Studio.

Sun Microsystems has taken an initiative called Sun ONE (Open Network Environment) and is planning to push Java forward as a platform for Web services. It is developing Java APIs for XML-based remote procedure calls and for looking up services in XML registries – two more JAX family APIs: JAX/RPC (Java API for XML Remote Procedure Calls) and JAXR (Java API for XML Registries). These will wrap up implementations of Web services standards, such as SOAP and UDDI.

IBM also for its part has already developed a suite of early-access tools for Web services development. They are Web Services Toolkit (WSTK), WSDL Toolkit, and Web Services Development Environment (WSDE).

Apache Axis is an implementation of the SOAP (“Simple Object Access Protocol”) submission to W3C.

From the draft W3C specification:

SOAP is a lightweight protocol for exchanging structured information in a decentralized, distributed environment. It is an XML based protocol that consists of three parts: an envelope that defines a framework for describing what is in a message and how to process it, a set of encoding rules for expressing instances of application-defined datatypes, and a convention for representing remote procedure calls and responses.

Apache Axis is an Open Source SOAP server and client. SOAP is a mechanism for inter-application communication between systems written in arbitrary languages, across the Internet. SOAP usually exchanges messages over HTTP: the client POSTs a SOAP request, and receives either an HTTP success code and a SOAP response or an HTTP error code. Open Source means that you get the source, but that there is no formal support organization to help you when things go wrong.

Conclusion

For the last few years, XML has enabled heterogeneous computing environments to share information over the Web. It now offers a simplified means by which to share process as well. From a technical perspective, the advent of Web services is not a revolution in distributed computing. It is instead a natural evolution of XML application from structured representation of information to structured representation of inter-application messaging.

Prior to the advent of Web services, enterprise application integration (EAI) was very difficult due to differences in programming languages and middleware used within organizations. This led to the situation where interoperability was cumbersome and painful. With the arrival of Web services, any application can be integrated as long as it is Internet-enabled.

It is difficult to avoid the popularity and hype that is surrounding Web services. Each software vendor has some initiative concerning Web services and there is always great speculation about the future of the market for them. Whichever way it turns out, Web service architectures provide a very different way of thinking about software development. From client-server to n-tier systems, to distributed computing, Web service applications represent the culmination of each of these architectures in combination with the Internet.

Creating webservices in NetBeans.

In this example program I will show you how you can make webservices in the Netbeans IDE. NetBeans IDE provides necessary GUI Tool to help the developers to quickly develop and deploy web services.

In this example we will

a) Develop webservices

b) Test the webservice

c) Develop client and call the webservice there

d) Finally deploy and test the application

Web Service can be added in a Web project or in Ejb project. Netbeans IDE helps the developers to easily develop and test the webservices.
It’s easy to make the Web Service program in Netbeans, which has Glassfish server by default.

Web Service program in Web Project

In Netbeans take new web project in figure 1

Web Services Example

Figure 1

Give project name webservice1 as shown in figure 2

Web Services Example

Figure 2

Select the server name in figure 3

Web Services Example

Figure 3

Now Rt Click on the Web Service project in figure 4

Select New->WebService

Web Services Example

Figure 4

Now give the name of the Web Service and package name figure 5

Web Services Example

Figure 5

Now In design view of Web Service click on Add Operation in figure 6

Web Services Example

Figure 6

Here give the operation name and parameter name and type as shown in figure 7

Web Services Example

Figure 7

Now in source view change the return null to return “hello ”+name as in figure 8

Web Services Example

Figure 8

Now Rt Click on the project and deploy it on the server as in figure 9

Web Services Example

Figure 9

It will deploy the war file on to the server

Now test the web service program

Rt click on the MyWebService in web services folder and select Test Web Operation as in figure 10

Web Services Example

Figure 10

It will open the Web Service program in browser as in figure 11

Web Services Example

Figure 11

Click on WSDL File in blue color .It will open the WSDL file in the browser as in figure 12

Web Services Example

Figure 12

Now as in fig type the roseindia in the text field and click on show button as in figure 13

Web Services Example

Figure 13

It will return hello roseindia

It also give the SOAP request and SOAP response pf the Web Service as in figure 14

Web Services Example

Figure 14

Now make the client file.Client file can be java servlet , jsp and standalone java file

Start a new web project as in figure 15.

Give project name as Webservice1-client

Web Services Example

Now Rt. Click on the project select NewàWeb Service client

Here now select the WSDL file of the Web Service as in figure 15

Click on the Browse.

Web Services Example

Now select the webservice1àMyWebService

Web Services Example

Figure 15

It creates the Client environments for the Web Service in the given project

Now make a Client file by just taking a new Jsp file as in figure 16

Web Services Example

Figure 16

Give the file name as client.jsp

Rt click in client.jsp file code and select Web Service Client resources –>Call Web Service Operation in figure 17

Web Services Example

Figure 17

Select the web service project ->web service file->web service port->operation name as in figure 18

Web Services Example

Figure 18

Change the name =”null” to name=”roseindia” as in figure 19

Web Services Example

Figure 19

Rt click in client.jsp and select run client.jsp

Web Services Example

Download Code

Java PDF Generation with IText

Posted: January 4, 2012 in Random Posts
Tags: , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , ,

Multi Site Keyword Extractor Tool
Analyze Keywords

First Method creates ur PDF File and Second Download your file from the relative Path in JSF

public String mypdfGeneratorAmd() {
// fileCreation();
List mylist = this.getListDfAmd();
if (mylist != null) {
Document pdf = new Document();
Date today = new Date();
ServletContext servletContext = null;
// (ServletContext)
// FacesContext.getCurrentInstance().getExternalContext().getContext();
// String logo1 = servletContext.getRealPath(“”) + “/” +
// “WebContent”
// + “/” + “reports” + “/”;

String fileName = “AssistedMaintenanceDocking.pdf”;

File f;
String fileTitle = “AssistedMaintenanceDocking ”
+ (new Date().toString());
servletContext = (ServletContext) FacesContext.getCurrentInstance()
.getExternalContext().getContext();
String logo = servletContext.getRealPath(“”) + “/” + “images” + “/”
+ “user-image.jpg”;

int rowCount = mylist.size();
PdfPTable t = new PdfPTable(5);
Paragraph title1 = new Paragraph();
try {
Image img = Image.getInstance(logo);
String mypdfFile = servletContext.getRealPath(“”) + “/”
+ “reports” + “/” + “DefectAndHistory.pdf”;
f = new File(mypdfFile);
// “/home/shussain/workspace2/DNRMS-PMSA/WebContent/reports/”+
// “AssistedMaintenanceDocking.pdf”);
if (!f.exists()) {
try {
f.createNewFile();
System.out
.println(“New file ‘AssistedMaintenanceDocking.pdf’ has been created to the current directory”);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
} else {
System.out
.println(“File ‘AssistedMaintenanceDocking.pdf’ Already in the current directory”);
}
PdfWriter.getInstance(pdf, new FileOutputStream(f));
pdf.addTitle(fileTitle);
pdf.setMargins((float) 1.5, (float) 1.5, 30, 30);
pdf.addAuthor(session.getAttribute(“sessionUserName”)
.toString());
pdf.addCreationDate();
pdf.addCreator(session.getAttribute(“sessionUserName”)
.toString());
pdf.addSubject(“Assisted Maintenance Docking”);
pdf.open();

title1.add(new Paragraph(“Assisted Maintenance Docking” + “\n”
+ (new Date().toString()), FontFactory.getFont(
FontFactory.HELVETICA, 20, Font.BOLD,
new Color(0, 0, 0))));
title1.setAlignment(“CENTER”);
Chapter chapter1 = new Chapter(title1, 1);
chapter1.setNumberDepth(0);

pdf.add(chapter1);
addEmptyLine(title1, 2);
Phrase phraseOfImage = new Phrase();
phraseOfImage.add(new Chunk(img, 18, -18));
pdf.add(phraseOfImage);

pdf.add(Chunk.NEWLINE);
pdf.add(Chunk.NEWLINE);

t.setWidthPercentage(90);
Phrase phrase1 = null;

float[] columnWidths = { 200, 200, 200, 200, 200 };
t.setWidths(columnWidths);

PdfPCell c1 = new PdfPCell(new Phrase(“Ship/Unit”,
FontFactory.getFont(FontFactory.HELVETICA, 12,
Font.BOLD, Color.BLACK)));

c1.setBackgroundColor(Color.gray);
c1.setHorizontalAlignment(Element.ALIGN_CENTER);
t.addCell(c1);

c1 = new PdfPCell(new Phrase(“Last AMD”, FontFactory.getFont(
FontFactory.HELVETICA, 12, Font.BOLD, Color.BLACK)));
c1.setBackgroundColor(Color.gray);
c1.setHorizontalAlignment(Element.ALIGN_CENTER);
t.addCell(c1);

c1 = new PdfPCell(new Phrase(“AMD Plan”, FontFactory.getFont(
FontFactory.HELVETICA, 12, Font.BOLD, Color.BLACK)));
c1.setBackgroundColor(Color.gray);
c1.setHorizontalAlignment(Element.ALIGN_CENTER);
t.addCell(c1);

c1 = new PdfPCell(new Phrase(“Duration”, FontFactory.getFont(
FontFactory.HELVETICA, 12, Font.BOLD, Color.BLACK)));
c1.setBackgroundColor(Color.gray);
c1.setHorizontalAlignment(Element.ALIGN_CENTER);
t.addCell(c1);

c1 = new PdfPCell(new Phrase(“Package”, FontFactory.getFont(
FontFactory.HELVETICA, 12, Font.BOLD, Color.BLACK)));
c1.setBackgroundColor(Color.gray);
c1.setHorizontalAlignment(Element.ALIGN_CENTER);
t.addCell(c1);

t.setHeaderRows(1);

for (int i = 0; i < rowCount; i++) {

dfamd = (DfAmd) mylist.get(i);
t.addCell(dfamd.getDfShipUnits().getShip());

t.addCell(dfamd.getLastAmd());
t.addCell(dfamd.getAmdPlan());
t.addCell(dfamd.getDuration());
t.addCell(dfamd.getPackage_());

}

pdf.add(t);

// section1.add(t);
pdf.setPageSize(PageSize.A4);

pdf.add(pdf.getPageSize());

} catch (DocumentException e) {
System.err.println(e.getMessage());
} catch (IOException ex) {
System.err.println(ex.getMessage());
}
pdf.close();
try {
downloadPDF();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
} else {
msging = new FacesMessage(FacesMessage.SEVERITY_WARN, "Error",
"Your Report Is Empty Please Search Some Data");
// msging ="Your Report Is Empty Please Search Some Data";

}
FacesContext.getCurrentInstance().addMessage(null, msging);
return "success";
}

// put new line after specific Element
private static void addEmptyLine(Paragraph paragraph, int number) {
for (int i = 0; i 0) {
output.write(buffer, 0, length);
}

// Finalize task.
output.flush();
} finally {
// Gently close streams.
close(output);
close(input);
}

facesContext.responseComplete();
}

private static void close(Closeable resource) {
if (resource != null) {
try {
resource.close();
} catch (IOException e) {

e.printStackTrace();
}
}
}

 

4  

Acceleo JavaEE Generators (Helios version) 2.2

Acceleo Java EE Generators provides a set of code generators targetted to the populars Java/JavaEE frameworks: JPA/Hibernate Spring Framework Struts JSP … You can choose …

Last Updated on 22 December 2011 by Obeo

4  

LWJGL Plugin 2.8.2

The Lightweight Java Game Library (LWJGL) is a Java library wrapping OpenGL and OpenAL. It comes with some JARs and native libraries.

Last Updated on 22 December 2011 by Jens von Pilgrim

4  

Feature Explorer View 1.0.1

This view explores Features. It enables you to quickly search your target platform to find the feature where the plugin you need is located.

Last Updated on 22 December 2011 by Wim Jongman

24  

Jaspersoft Studio 1.0.6

Jaspersoft Studio is a free, open source report designer for JasperReports. A full rewrite of iReport on top of Eclipse available as plugin and standalone application.

Last Updated on 22 December 2011 by Giulio Toffoli

1  

Jspresso Developer Studio Translation 1.0.0

Jspresso Developer Studio Translation helps you to manage your resource bundles internationalisation (i18n) property files by editing them directly from within your java editor …

Last Updated on 21 December 2011 by Maxime

1  

FDT 5.0

FDT 5 is a flexible development toolkit in Eclipse for interactive developers. It´s made with passion for expert Flash and Flex coding, innovative mobile development and …

Last Updated on 21 December 2011 by Alan Klement

0  

Product

Last Updated on 21 December 2011 by Alan Klement

0  

Zend Studio – Eclipse based PHP IDE

Zend Studio is the leading Integrated Development Environment (IDE) built on the Eclipse platform. Incorporating all the capabilities of the latest Eclipse release, features …

Last Updated on 21 December 2011 by Orly Maman

3  

Eclipse Todo Editor 1.1.0

Manage your todos in an easy to use text editor with syntax highlighting and code completion. Effectively structure and query your todo lists using projects and custom tags. …

Last Updated on 20 December 2011 by Sebastian Benz

42  

InstaSearch 1.3

InstaSearch is an Eclipse plug-in for doing fast text search in the workspace. The search is performed instantly as-you-type and resulting files are displayed in an Eclipse …

Last Updated on 20 December 2011 by Andrejs Jermakovics

Showing 1-10 of 50
 

I’ve been working with JavaServer Faces (JSF) a lot lately, and one thing I was curious about was how I can get back to the old-fashioned Java session (HttpSession) if and when I need to, while also wondering what was in the session.

Here’s some sample Java code that shows how you can access the traditional session from your own JSF code, and also prints whatever is in that session. As you can see, it takes essentially one or two lines of code to get to the HttpSession reference:

FacesContext facesContext = FacesContext.getCurrentInstance();
HttpSession session = (HttpSession) facesContext.getExternalContext().getSession(false);
Enumeration e = session.getAttributeNames();
while (e.hasMoreElements())
{
String attr = (String)e.nextElement();
System.err.println(” attr = “+ attr);
Object value = session.getValue(attr);
System.err.println(” value = “+ value);
}