Archive

Archive for February, 2012

Reload a class without restarting tomcat

February 29, 2012 Comments off

Step 1: Open tomcat_dir/conf/context.xml

Step 2: Change  from <context>  to <context reloadable=”true”> then save the changes

Step 3: Open tomcat_dir/conf/server.xml

Step 4: Add the following lines

<Context path=”” docBase=”ROOT” debug=”0″/>
<DefaultContext reloadable=”true”/>

Step 5: Save the changes and restart the tomcat server, now servlet class changes can work without restarting tomcat server

 

 

Advertisements
Categories: J2EE, JSP, Technical

First JSP Servlet application

February 29, 2012 Comments off

Note: for any changes in servlet class, you have to restart the tomcat server to see the changes 😦

LoginFormServlet.jsp

———————————–

<html>
<head>
<title>Login Form</title>
<style type=”text/css”>
div {
margin: 250px,450px;
}
</style>
</head>
<body>
<form action=”/LoginValidation” method=”post” align=center>
<div>
<table border=0>
<tr>
<td>
User Name:
</td>
<td>
<input type=”text” name=”user” />
</td>
</tr>
<tr>
<td>
Password:
</td>
<td>
<input type=”password” name=”pass” />
</td>
</tr>
<tr>
<td colspan=2 align=right>
<input type=”submit” value=”Submit” >
</td>
</tr>
</table>
</div>
</form>
</body>
</html>

LoginValidation.java (Servlet Class)  Compile and copy the class file to Classes folder

———————————————————-

import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class LoginValidation extends HttpServlet
{
public void doGet(HttpServletRequest request,HttpServletResponse response)
{

try
{
String userName = request.getParameter(“user”);
String passWord = request.getParameter(“pass”);
PrintWriter out = response.getWriter();

if(userName.equals(“karu”)  && passWord.equals(“karuvachi”))
{
out.println(“Congratulations… you can work on this application :-)”);
}
else
{
out.println(“Sorry… you cannot work on this application :-(“);
}
}catch(Exception e) { System.out.println(e);}
}
public void doPost(HttpServletRequest request,HttpServletResponse response)
{
doGet(request,response);
}
}

web.xml

——————————-

<web-app>

………………………………………….

………….

<servlet>
<servlet-name>LoginValidation</servlet-name>
<servlet-class>LoginValidation</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>LoginValidation</servlet-name>
<url-pattern>/LoginValidation</url-pattern>
</servlet-mapping>

</web-app>

Categories: J2EE, JSP, Technical

Editing a environment variable in windows

February 28, 2012 Comments off

Go to Control Panel – > System->Advanced->Environment variable

Choose the variable and edit

For Example

Choose “PATH” , add c:\jdk\bin

 

Categories: J2EE, Technical

JSP Directives

February 28, 2012 Comments off

page,include,taglib are the three directives in JSP

page is used to edit the attributes of a page.

include is used to import the java packages.

taglib is used to import the tag libraries.

Categories: J2EE, JSP, Technical

Login Form in JSP

February 28, 2012 Comments off

LoginForm.jsp

—————————————————————————-

<html>
<head>
<title>Login Form</title>
<style type=”text/css”>
div {
margin: 250px,450px;
}
</style>
</head>
<body>
<form action=”LoginValidation.jsp” method=”post” align=center>
<div>
<table border=0>
<tr>
<td>
User Name:
</td>
<td>
<input type=”text” name=”user” />
</td>
</tr>
<tr>
<td>
Password:
</td>
<td>
<input type=”password” name=”pass” />
</td>
</tr>
<tr>
<td colspan=2 align=right>
<input type=”submit” value=”Submit” >
</td>
</tr>
</table>
</div>
</form>
</body>
</html>
LoginValidation.jsp

—————————————————————————-

<html>
<head>
<title> Login Validation </title>
</head>
<body>
<%
String userName = request.getParameter(“user”);
String passWord = request.getParameter(“pass”);
boolean valid = false;
if(userName.equals(“karu”) && passWord.equals(“karuvachi”))
valid=true;
if(valid == true)
{
%>
Congratulations, you can work on this application 🙂
<%
}
else
{
%>
Sorry, you cannot work on this application 😦
<%
}
%>
</body>
</html>

Categories: J2EE, JSP, Technical

How to center a form in html?

February 28, 2012 Comments off

Using div tag’s margin attribute we can center a form:

margin: 10px,10px,10px,10px;

(top, right, bottom, left)

 

<html>
<head>
<title>Login Form</title>
<style type=”text/css”>
div {
margin: 250px,450px;
}
</style>
</head>
<body>
<form>
<div>

you context here

</div>

</form>
</body>
</html>

 

 

Categories: Technical

Implicit Objects in JSP

February 28, 2012 Comments off

There are some objects implicitly available in JSP for easy development of web application

out,request , response, session, application, exception, page, pageContext,  config

out: its an instance of JspWriter class, can use this object to send the outputstream to web client.

request: its an instance of HTTPServletRequest class, can use this object to get the request details of a JSP Page from a web client such as info abt query string, query header, cookies…etc

response: its an instance of HTTPServletResponse class, can use this object to send the response to web client.

session:its an instance of HTTPSession class, can use this object to track information of a particular client between multiple requests, its more helpful on stateless HTTP requests.

application:its an instance of ServletContext class,can use this object to get information abt the JSP Container.

exception:its an instance of Exception class,can use this object to throw the exceptions from previous JSP pages.

page:Its an instance of HTTPJspPage class, can use this object to call any method in page’s servlet.

pageContext:its an instance of jsp.pageContext class, can use this object to get attributes of a page

config:its an instance of ServletConfig class, can use this object to get the initialize parameters of servlet.

Categories: J2EE, JSP, Technical