123ArticleOnline Logo
Welcome to 123ArticleOnline.com!
ALL >> Computer-Programming >> View Article

Asp Dot Net - Play Together With Java Applets

Profile Picture
By Author: mayur aegis
Total Articles: 64
Comment this article
Facebook ShareTwitter ShareGoogle+ ShareTwitter Share

Is your web application platform for Java development based on ASP(dot)net technology? Then Java developers can leverage the Java platform for rich user experience of users visiting the website developed under outsource Java development. Java developers can develop secure rich internet applications with the use of Java or JavaFX language. This technology integrates seamlessly with ASP(dot)net and here we are going to explore various mechanisms by which Java applets can interact with ASP(dot)net web pages.

* View Applet - ASP(dot)net Interaction: First we will see a short screencast which will show the way an applet interacts with ASP .net page. It would make Java developers to understand the context given in the rest of this article.
* Deploying an Applet in an ASP(dot)net Page: By using deployment toolkit script for deploying an applet in an ASP(dot)net page can be done by following code snippet:

Default.aspx


...


var attributes = { width:675, height:300} ;
var parameters = { jnlp_href: 'applet/map-applet(dot)jnlp'};
deployJava.runApplet(attributes, parameters, ...
... '1.6');

...


ASP .net, We Need To Talk:

While Java application development for proper interaction of an applet with the ASP .net page can be done with the use of following mechanisms:

1. Cookies: Applet can set and retrieve cookies set by ASP(dot)net pages.
2. Updating HTML elements and ASP(dot)net controls - An applet can update the values of HTML elements and ASP(dot)net controls in the parent web page by using the LiveConnect feature.
3. Directly invoking an ASP(dot)net page - An applet can use the java(dot)net(dot)URLConnection class to invoke an ASP(dot)net page, pass parameters to the page, and retrieve a response.

Modes of Interaction:

You can use cookies for sharing data between applet and page. Cookies are retrieved by applet and set by an ASP (dot)net page and vice versa. In the codesnippet shown next, the MapApplet class uses the java(dot)net(dot)CookieHandler class to retrieve the userName cookie set by the applet's parent web page. The text "Hello " is displayed on the top left corner of the applet.

private void getUserNameFromCookie() {
try {
// get the cookies that are applicable for this applet's parent web page
URL docBaseUrl = this.getDocumentBase();


CookieHandlercookieHandler = CookieHandler.getDefault();
java.util.Map headers =
cookieHandler.get(docBaseUrl.toURI(),
new HashMap());
if (headers.isEmpty()) {
System.out.println("No cookies found!");
} else {
getUserNameFromHeader(headers);
}
} catch(Exception e) {
...
}
}

private void getUserNameFromHeader(java.util.Map headers) {
for (String key : headers.keySet()) {
for (String value : headers.get(key)) {
if (key.equals("Cookie") &&value.startsWith("userName")) {
userName = value.split("=")[1];
}
}
}
}

Updating ASP (dot)net Page With LiveConnect :

For interaction of applet with code in its parent web pages can be done with the use of LiveConnect feature. Applet is supposed to invoke JavaScript functions and access its variables for updating the contents of its parent web page. JavaScript code in the web page can also invoke applet methods.In the following code snippet, the MapApplet class uses an instance of thenetscape(dot)javascript(dot)JSObject class to update the contents of the asp:TextBox ID="addresses" control.

MapApplet(Dot)java

public void updateWebPage(String street, String city, String state) {
char result = invokeAspPage(street, city, state);
if (result == '1') {
window.call("writeAddressOnPage", new Object[] {street, city, state});
}
}

Default(Dot)aspx


...

function

writeAddressOnPage(street, city, state) {
var address = street + ", " + city + ", " + state;
var form = document.getElementById("addrForm");
varprevValue = form.elements["addresses"].value;
form.elements["addresses"].value = prevValue + "\n" + address;
}


Addresses saved to your address book:
<
asp:TextBox ID="addresses"TextMode="MultiLine" Rows="6"
Columns="60" runat="server" >


...


During the time of posting of form the form fields values are available to the next page through the Request object. Developers can also choose to update hidden form field with the data of applet.

* Invoking an ASP .net Page: For invoking of ASP .net page by an applet can be done by the use of the java(dot)net(dot)URLConnection class. You will find the MapApplet class opening a connection to the FileWriter.aspx page in the below snippet. It passes parameters with the use of connection's output stream and then receives a result after reading the connection's input stream.

MapApplet(Dot)java

public char invokeAspPage(String street, String city, String state)

{
char [] result = {'0'};
...
String urlString = baseUrl + "FileWriter.aspx";
URL url = new URL(urlString);
URLConnection connection = url.openConnection();
connection.setDoOutput(true);
// send parameter to url connection
OutputStreamWriter out = new OutputStreamWriter(
connection.getOutputStream());
out.write("addresses=" + URLEncoder.encode(address, "UTF-8"));
out.close();
// read response from url connection
BufferedReader in = new BufferedReader(
new InputStreamReader(
connection.getInputStream()));
in.read(result);
in.close();
...
return result[0];
}

The FileWriter(dot)aspx page writes the given address information to theuserData/addresses.txt text file on the ASP .net server. The character value of "1" that is returned by the page and the address is written successfully. There are number of ways by which an applet is able to interact with the ASP .net page. Java developers are supposed to choose the option that works best during Java application development.

Source Code:

Developers can download the ASP .net project and Java code from below source files:

* MapViewer(Dot)java
* ASP(Dot)net Source Code
* Default(Dot)aspx
* Default.aspx(Dot)cs
* FileWriter(Dot)aspx
* FileWriter(Dot)aspx(Dot)cs

Resources

* Deployment Trail in the Java Tutorials
* Applets
* Doing More with Rich Internet Applications
* Deployment In-Depth

For More Inforamtion about ASP.net Development:- http://www.aegisisc.com/net-developers.html

Total Views: 253Word Count: 1046See All articles From Author

Add Comment

Computer Programming Articles

1. Which Are The Best Java Coding Classes In Bhopal?
Author: Shankar Singh

2. Warehouse Management In Zambia: Essential Features To Look For
Author: Doris Rose

3. Ecommerce Web Design And Development In Melbourne With The Merchant Buddy
Author: themerchantbuddy

4. Why Website Maintenance Is Crucial For Business Success
Author: Yogendra Shinde

5. Boost Your Business With Smart Invoice Pos Software In Zambia
Author: Cecilia Robert

6. How Stablecoin Development Ensures Stability And Security?
Author: Michael noah

7. Công Cụ Tính Chiều Cao Chuẩn Từ Minbin Tool: Đo Lường Và Cải Thiện Chiều Cao Hiệu Quả
Author: KenJi123

8. How To Make A Courier App For Courier Delivery And Tracking Service
Author: Deorwine Infotech

9. Reputation Management In The Digital Age: Protecting And Enhancing Your Law Firm’s Image
Author: jamewilliams

10. What Features Should I Look For In Wordpress Ecommerce Plugins?
Author: Rocket Press

11. Staying Updated With The Latest Gaming News
Author: Next Tech Plus

12. Game Development: Evolving Technologies And New Horizons
Author: Rick John

13. Why Svelte Is The Most In-demand Framework For Web Development?
Author: Why Svelte Is The Most In-Demand Framework For Web

14. Maximizing Ebay Sales With Maropost/neto And Pursuit Info Solutions
Author: rachelvander

15. The Importance Of Software Testing: Ensuring Quality In Development
Author: John Mathew

Login To Account
Login Email:
Password:
Forgot Password?
New User?
Sign Up Newsletter
Email Address: