Search This Blog

Showing posts with label HTML/JS. Show all posts
Showing posts with label HTML/JS. Show all posts

Thursday, October 1, 2009

Call Parent window method from Child Window using JavaScript

In this week I have solved three technical problems while working in TMS (Transport Management System) application.

Problems:

  1. In html need to call a parent window method from the child window.
  2. com.sun.tools.Main class found error while starting the Tomcat ( After new installation of Tomcat)
  3. Tomcat cannot support JDK1.5 error.

Solution 1:

    • In html need to call a parent window method from the child window.

In my application I have to call a parent window method from child window method for setting value in parent window.

Example:

  1. Parent window has Method as PrentMethod()
  2. Child window has Method as ChildMethod();
  3. Inside Child window method ChildMethod() we have to call parent window method ParentMethod() like window.opener.ParentMethod();

Refer the below link for more information

http://www.codingforums.com/archive/index.php/t-36165.html

Solution 2:

com.sun.tools.Main class found error while starting the Tomcat ( After new installation of Tomcat)

To solve this issue we have to include the tools.jar file in Tomcat.

Steps:

1. copy the tools.jar file from C:\Program Files\Java\jdk1.5.0_06\lib\tools.jar

2. paste the same into the tomcat common lib directory (D:\Program Files\Apache Software Foundation\Tomcat 5.0\common\lib\tools.jar)

3. Now restart the server you wont get the com.sun.tools.Main class not found exception.

Solution 3:

Tomcat cannot support JDK1.5 error.

While working with tomcat 5.0 we seem to get Virtual machine does not support generics (JDK1.5 features). So the JSP file can’t compile.

If we want to enable jdk1.5 feature support, we have to supply two initial parameter for JspServlet class present in web.xml(\tomcat5.0\config.xml)

Two initial parameters are:

  1. compilerSourceVM
  2. compilerTargetVM

Default:

jsp

org.apache.jasper.servlet.JspServlet

fork

false

xpoweredBy

false

3

After Change:

jsp

org.apache.jasper.servlet.JspServlet

fork

false

xpoweredBy

false

3

compilerSourceVM

1.5

compilerTargetVM

1.5

Saturday, September 5, 2009

HTML Multiple CheckBOX problem and solution

when we have more than one cheque(checkbox) in a list then only length of the cheque will be return otherwise that particular chceck box will be consider as single value.so the length of the checkbox will be return as null.

Tuesday, July 14, 2009

In HTML Reload Parent window from child window:

In HTML Reload Parent window from child window:

When I am working for a client, I have received one requirement.

Requirement IS:

Re-Load the parent window when ever clicking button in Child window.

Solution:

1. Consider two file called parent_window.html and child_window.html.

2. Open child window from parent window using javascript.

Window.open(“child_window.html”);

3. In child_window.html write javascript function called reloadParentWindow()

Function loadParentWindow()

{

If (opener)

Opener.location.reload();

}

You can call this function from child window.

function reloadParentWindow(){

//////this line of code will actually reload the parent window

if(opener)opener.location.reload();

}

Opener keyword returns the reference of the parent windows objects.

Friday, December 12, 2008

AJAX-Introduction

Ajax Documentation:

Ajax definition:

  1. AJAX stands for Asynchronous Java script and XML.
  2. It’s a web development technique for creating interactive web-based application that can asynchronously interchange data between client and Server.

Definition 2:

AJAX is a technique rather than a technology: It describes how JavaScript can be used to pull data from the server using the XML HTTP Request object and then insert this data into the website using DOM. This is done asynchronously - that is, in the background, without having to refresh the whole page.

DOM (Document object Model):

  1. DOM is an internal representation of the website.
  2. DOM is accessible by the java script and provide the way to programmatically insert, remove, modify in a n website..

Example program with DOM:

1. Below example show how to use DOM tag in java script.

Div tag also a DOM (Document object model.):

Code: dom.html

 

Replace Text

 
  Hello, world!

The above example shows how to set the content of the

element with the id "foo" to "Hello, AJAX world!”

Output:

Initial:

Replace Text

Hello,world!

After Clicked Replace Text:

Output:

Replace Text

Hello, AJAX world!

Example 2:

1. Check the username is available in database? If the username available print “username available “message. If not available (ie. same user name already exist in db) print message “username not available”.

1. <%@ page language="java" contentType="text/html; charset=ISO-8859-1"

2. pageEncoding="ISO-8859-1"%>

3.

4.

5.

6.

29.

30. Insert title here

31.

32.

33.

Please choose your username:

34.

35.

36.

37.

38.

39.

40.

Description:

Line 7: var http=false; > Initializing the http object reference variable that will hold the browser object .

Line 8 to 12: check browser type. If the browse type is Microsoft internet explorer we have to use the ActiveXObject .

http = new ActiveXObject("Microsoft.XMLHTTP");

Other wise we should use

http = new XMLHttpRequest();

Line 13 to 22: This JavaScript function is responsible for calling the another JSP file and validate the username is available in db.

Line 17: In this line we have to mention the action type either POST or GET and URL.

http.open("GET", "validate.jsp?name=" + user, true);

Line 18: http.onreadystatechange method we should check JSP (process complete or what) ready for response.

if(http.readyState == 4) {

document.getElementById('foo').innerHTML = http.responseText;

}

Different ready states are from 1 to 4 ,Ready state 4 is intimating all the process has completed is server .So we can display result for the corresponding DOM.

Line 21: document.getElementById('foo').innerHTML = http.responseText;

Setting up the response into the foo div tag.

Validate.jsp

It’s a normal jsp page:

<%@ page import="java.util.*" %>

<%

String user="";

user=request.getParameter("name");

System.out.println("user="+new Date()+user);


if (user.equals("test"))

{

out.println("name is not available");

}

else

{

out.println("name is available");

}

%>

What ever you will be printing in out.println all the content will get response in the client side ( http.responseText) .