Java


If tomcat is failed on the server, Then login to the server with root login details and Goto, ————————-
cd /usr/local/jakarta/jakarta-tomcat-5.5.9/bin/
————————-
Check the running processes as
ps aux | grep tomcat
Then stop all tomcat processes. You can stop it with the script as ————————-
root@servername [/usr/local/jakarta/jakarta-tomcat-5.5.9/bin]# ./shutdown.sh ————————- [This script will stop the tomcat processes that are running]
In order to fix tomcat run following command under /usr/local/jakarta/jakarta-tomcat-5.5.9/bin
————————-
root@servername [/usr/local/jakarta/jakarta-tomcat-5.5.9/bin]# java -jar bootstrap.jar
————————- [This will set java environment for tomcat on the server]
Then start the tomcat service with the script
————————-
root@servername [/usr/local/jakarta/jakarta-tomcat-5.5.9/bin]# ./setclasspath.sh
root@servername [/usr/local/jakarta/jakarta-tomcat-5.5.9/bin]# ./startup.sh ————————- [This script start tomcat on the server]
You will have to stop and restart apache service on the server many times before you run startup.sh script.

It is easy to read the cookies from a servlet.
Cookies[] getCookies() returns an array of Cookie objects.

// Check for cookies
Cookie[] cookies = request.getCookies();

// Check to see if any cookies exists
if (cookies != null)
{
for (int i =0; i< cookies.length; i++)
{
Cookie aCookie = cookies[i];
System.out.println (“Name : “ + aCookie.getName());
System.out.println (“Value: “ + aCookie.getValue());
}
}

Class javax.servlet.http.cookies can be used to access cookies on the client side. The following code demonstrates this technique. It checks the existence of cookie ‘MyCookie’.

boolean dcookiefound = false;

Cookie[] cookies = request.getCookies();

for(int nIndex=0;nIndex < cookies.length;nIndex++)
{
if(cookies[nIndex].getName().equals(“MyCookie”))
{
dcookiefound = true;
//desired cookie found, use it
}

}

if(dcookiefound == false)
{
//cookies not found.
}

Here is a simple example to select a row from a database and to display that information.
/*== database constants ==*/
string dbhost = “localhost”;
string dbname = “directory”;
string dbuser = “webuser”;
string dbpass = “–password–”;

string dbdriver = “org.gjt.mm.mysql.Driver”;

/*== setup database driver and connect ==*/
Class.forName(DBDRIVER).newInstance();
string conurl = “jdbc:mysql://”+dbhost+”/”+dbname;
Connection db = DriverManager.getConnection(conurl,dbuser,dbpass);

/*== create sql query and execute ==*/
string sql = ” SELECT firstname,lastname FROM users “;

Statement stmnt = db.createStatement();
ResultSet rs = stmnt.executeQuery(sql);
/*== display results ==*/
while (rs.next())
{
out.println(”Name: “+rs.getString(”firstname”)+ ” ” + rs.getString(”lastname”) +”\n”);
}

To create a popup menu you should set following parameters:

var popupMode=1;

To show a popup menu assign the following function call to event:

yourEvent = “return apy_popup(menuN, pause, event);”

Where:
yourEvent - event type (onMouseOver, onClick, onContextMenu, etc.)
menuN - menu number on page.
pause - inactivity delay.
event - reserved. Do not change.

A high-level programming language developed by Sun Microsystems. Java was originally called OAK, and was designed for handheld devices and set-top boxes. Oak was unsuccessful so in 1995 Sun changed the name to Java and modified the language to take advantage of the burgeoning World Wide Web.
Java is a general purpose programming language with a number of features that make the language well suited for use on the World Wide Web. Java is an object-oriented language similar to C++, but simplified to eliminate language features that cause common programming errors. Small Java applications are called Java applets and can be downloaded from a Web server and run on your computer by a Java-compatible Web browser, such as Netscape Navigator or Microsoft Internet Explorer. “Java” generally refers to a combination of three things: the Java programming language (a high-level, object-oriented programming language); the Java Virtual Machine (a high-performance virtual machine that executes bytecodes on a specific computing platform, typically abbreviated JVM); and the Java platform, a JVM running compiled Java bytecodes, usually calling on a set of standard libraries such as those provided by Java Standard Edition (SE) or Enterprise Edition (EE). Though coupled by design, the language does not imply the JVM, and vice versa.

Apache Tomcat is the servlet container that is used in the official Reference Implementation for the Java Servlet and JavaServer Pages technologies. Sun developed the Java Servlet and Java Server Pages specifications under the Java Community Process. Apache Tomcat is developed in an open and participatory environment and released under the Apache Software License. Apache Tomcat powers numerous large-scale, mission-critical web applications across a diverse range of industries and organizations.

Apache Tomcat Versions:

For different versions of the Servlet and JSP specifications there are different versions of Apache Tomcat available. The mapping between the specifications and the respective Apache Tomcat verisons is:

Servlet/JSP Spec Apache Tomcat version
2.5/2.1 6.0.x
2.4/2.0 5.5.x
2.3/1.2 4.1.x
2.2/1.1 3.3.x

Alpha / Beta / Stable:

Initially every Tomcat release is released as an Alpha release. After a week, a vote is held to gather views on the stability of the release. If a major issue is identified during testing, then the vote may not take place and the release will remain as an Alpha release. Stability is a subjective judgement and you should always read carefully the release notes for any version you intend to make use of.

Alpha releases may contain large amounts of untested/missing functionality required by the specification and/or signifcant bugs and are not expected to run stably for any length of time.

Beta releases may contain some untested functionlaity and/or a number of relatively minor bugs. Beta releases are not expected to run stably.

Stable releases may contain a small number of relatively minor bugs. Stable releases are intended for production use and are expected to run stably for extended periods of time.

Introduction to Struts

Apache Struts is a free open-source framework for creating Java web applications.

Web applications differ from conventional websites in that web applications can create a dynamic response. Many websites deliver only static pages. A web application can interact with databases and business logic engines to customize a response.

Web applications based on JavaServer Pages sometimes commingle database code, page design code, and control flow code. In practice, we find that unless these concerns are separated, larger applications become difficult to maintain.

One way to separate concerns in a software application is to use a Model-View-Controller (MVC) architecture.

Basic idea behinds MVC architecture is to separate your business logic and presentation part separate.so if design changes it does not affect business logic.

The Struts framework is designed to help developers create web applications that utilize a MVC architecture.

The framework provides three key components:

  • A “request” handler provided by the application developer that is mapped to a standard URI.
  • A “response” handler that transfers control to another resource which completes the response.
  • A tag library that helps developers create interactive form-based applications with server pages.

The framework’s architecture and tags are buzzword compliant. Struts works well with conventional REST applications and with technologies like SOAP and AJAX.

This framework enables design and implementation of large web applications to be handled by different groups of people. In other words, page designers, component developers and other developers can handle their own bit of the project, all in tandem and in a decoupled manner. It features I18N(internationalization), a powerful custom tag library, tiled displays and form validation. It also supports a variety of presentation layers, including JSP, XMl/XSLT,Java Server Faces (JSF), as well as a variety of model layers, includingJava Beans and EJB.

Java is very powerful saftware platform. More than that it is platform independent. Java is Object Oriented language. Java is mainly used for following purpose

Java can be used to develope web based application along with stand alone application.

Using swing & Java 2D toolkit we can create sofisticated GUI

The JDK provides standard mechanisms, such as Java Web Start and Java Plug-In, for deploying your applications to end users.

Java also provides integration libraries such as JDBC, JNI,RMI etc for database access & remote object manipulation.

With J2EE (Java 2 Enterprise Edition)we can we can develope enterprise application

The Java Platform, Micro Edition (Java ME) provides a robust, flexible environment for applications running on consumer devices, such as mobile phones, PDAs, TV set-top boxes, printers and a broad range of other embedded devices.