MCSL 54

You might also like

Download as doc, pdf, or txt
Download as doc, pdf, or txt
You are on page 1of 41

E1.

Verify Installation and setting of Web Container / Web Server / Tomcat and prepare an Installation report, which
contains setting of class path. Server port, starting and shutting down of server etc.
-----------------------------------------------------------------------------------------------------------
Installing Tomcat
This is a brief "how-to" for installing Tomcat on a Windows PC.
Installing Java
Tomcat requires java in order to run. If your computer already has java installed, you can probably skip this step.
However, make sure you have a recent version of java. Here I provide instructions for installing version 1.4.2 of the
Java 2 Platform, Standard Edition (J2SE).
Steps for installing java
1. Go to the download page of J2SE Version 1.4.2.
2. Select the version for Windows and click through the license acceptance. After two pages, you will be able to
download the EXE file for installing java on windows. Look for the SDK version.
3. Download and run the EXE installation program.
4. You will need to accept the license agreement again.
5. Use the suggested directory for installing java (C:\j2sdk1.4.2_01).
6. You may use the remaining default settings for the installation.
Setting the Java Environment Variable
Tomcat will need to know where you have installed java. To do this, you will need to set the environment variable
JAVA_HOME to C:\j2sdk1.4.2_01 (where you installed java).
Here are the steps for setting the environment variable on my computer (Windows XP Professional). The steps will
probably be similar for other Windows computers.
1. Open the control panel under the start menu.
2. Double-click on System.
3. Click on the Advanced tab.
4. Click on the Environment Variables button.
5. Under System Variables, click on the New button.
6. For variable name, type: JAVA_HOME
7. For variable value, type: C:\j2sdk1.4.2_01
8. Continue to click OK to exit the dialog windows.
Installing Tomcat
After setting the JAVA_HOME environment variable, you can install tomcat.
1. Go to the Tomcat Web page.
2. Click on Binaries under the Download label on the left side of the page.
3. Scroll down until you see Tomcat 4.1.x. (x will be some number greater than 10).
4. Click on the link ending with exe (e.g. 4.1.27 exe).
5. Download and run the exe file.
6. I suggest you install Tomcat at c:\tomcat4
7. Use the default settings and provide a password that you will remember.
8. now assume that your tomcat are installed at c:\tomcat4
Running Tomcat
Here are the steps to see if Tomcat has been successfully installed
1. Start Tomcat by finding its start program in the Programs Menu (located in the Start menu). Look under Apache
Tomcat 4.1 and select "Start Tomcat".
2. Open a Web browser and type in the following URL:
o http://localhost:8080/
At this point, you should see the Tomcat home page, which is provided by the Tomcat Web server running on your
computer. Note: if your computer has an internet name or an IP number, you may access your Tomcat server
anywhere on the internet by substituting localhost with the full name or IP number.
To shut down your server and remove the Console window, select "Stop Tomcat" in the same menu of where you
selected "Stop Tomcat".
. Set Your CLASSPATH
Since servlets and JSP are not part of the Java 2 platform, standard edition, you have to identify the servlet classes
to the compiler. The server already knows about the servlet classes, but the compiler (i.e., javac) you use for
development probably doesn't. So, if you don't set your CLASSPATH, attempts to compile servlets, tag libraries, or
other classes that use the servlet and JSP APIs will fail with error messages about unknown classes. Here are the
standard Tomcat locations:
Tomcat 4: c:\tomcat4\common\lib\servlet.jar
in addition to the servlet JAR file, you also need to put your development directory in the CLASSPATH. Although this
is not necessary for simple packageless servlets, once you gain experience you will almost certainly use packages.
Compiling a file that is in a package and that uses another class in the same package requires the CLASSPATH to
include the directory that is at the top of the package hierarchy. In this case, that's the development directory I just
discussed. Forgetting this setting is perhaps the most common mistake made by beginning servlet programmers!
Finally, you should include "." (the current directory) in the CLASSPATH. Otherwise, you will only be able to compile
packageless classes that are in the top-level development directory.
Here are two representative methods of setting the CLASSPATH. They assume that your development directory is C:\
Servlets+JSP. Replace install_dir with the actual base installation location of the server. Also, be sure to use the
appropriate case for the filenames, and enclose your pathnames in double quotes if they contain spaces.
• Windows 98/Me. Use the autoexec.bat file.
o Tomcat 4
Sample code: (Note that this all goes on one line with no spaces--it is broken here only for readability.)
set CLASSPATH=.; C: \Tomcat4\common\lib\servlet.jar
Sample file to download and modify: autoexec.bat
Note that these examples represent only one approach for setting the CLASSPATH. Many Java integrated
development environments have a global or project-specific setting that accomplishes the same result. But these
settings are totally IDE-specific and won't be discussed here. Another alternative is to make a script whereby -
classpath ... is automatically appended onto calls to javac.
• Windows NT/2000/XP. You could use the autoexec.bat file as above, but a more common approach is to use
system settings. On WinXP, go to the Start menu and select Control Panel, then System, then the Advanced tab,
then the Environment Variables button. On Win2K/WinNT, go to the Start menu and select Settings, then Control
Panel, then System, then Environment. Either way, enter the CLASSPATH value from the previous bullet.
Enable the Invoker Servlet
The invoker servlet lets you run servlets without first making changes to your Web application's deployment
descriptor (i.e., the WEB-INF/web.xml file). Instead, you just drop your servlet into WEB-INF/classes and use the
URL http://host/servlet/ServletName (or http://host/webAppName/servlet/ServletName once you start using your
own Web applications). The invoker servlet is extremely convenient when you are learning and even when you are
doing your initial development. To enable the invoker servlet, uncomment the following servlet-mapping element in
c:\tomcat4\conf\web.xml. Also, do not confuse this Apache Tomcat-specific web.xml file with the standard one that
goes in the WEB-INF directory of each Web application. Finally, remember to make a backup copy of the original
version of this file before you make the changes.
<servlet-mapping>
<servlet-name>invoker</servlet-name>
<url-pattern>/servlet/*</url-pattern>
</servlet-mapping>
Create a simple web application
Here are the steps for running the class examples discussed on the first day.
1. Goto the following location on your computer: C:\Tomcat 4\webapps
o Create a directory “webdir” under C: \Tomca4\webapps, which will be your home directory for your assignment.
o Crate a directory “WEB-INF” under C: \Tomcat4\webapps \webdir
o Crate a directory “classes” under C: \Tomcat4\webapps\webdir\WEB-INF\, which will hold your servlet class files.
2. Goto http://127.0.0.1:8080/examples/servlets/helloworld.html, copy the java code and paste it into a blank file in
your editor (such as notepate), and save it as
c:\ Tomcat4\webapps\webdir\WEB-INF\classes\HelloWorld.java
3. Open a “Command Prompt” windows, and goto c:\ Tomcat4\webapps\webdir\WEB-INF\classes\
4. try “javac HelloWorld.java”
5. you will get a HelloWorld.class
6. Stop and restart Tomcat.
7. You can access the first example with the following URL:
o http://localhost:8080/webdir/servlet/HelloWorld
8. You can work at your own project based on webdir directory, and use some IDEs for programming, such as
Jcreator or EditPlus.

2.
E2.html

<html>
<title>Welcome Page</title>
<body>
<form method="post" action="/welservlet.do">
<h1 align=center>J2ee Programing</h1><br>
<h3>Enter Your Name:<input type="text" name="name"></h3>
<input type="submit" value="Click Me">
</form>
</body>
</html>

E2.java
import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;

public class e2 extends HttpServlet


{
public void doPost(HttpServletRequest req,HttpServletResponse res) throws IOException,ServletException
{
String msg=null;
String name=req.getParameter("name");
msg="Hi "+name+", Welcome to Servlet Programming";
res.setContentType("text/html");
PrintWriter out=res.getWriter();
out.println("<h1 align=center> Java Programing</h1>");
out.println("<br><h3>"+msg+"</h3><br>");
out.println("<br><h3>A Table with 5 rows and 5 columns</h3>");
out.println("<table border=1>");
out.println("<tr><td>1,1</td><td>1,2</td><td>1,3</td><td>1,4</td><td>1,5</td></tr>");
out.println("<tr><td>2,1</td><td>2,2</td><td>2,3</td><td>2,4</td><td>2,5</td></tr>");
out.println("<tr><td>3,1</td><td>3,2</td><td>3,3</td><td>3,4</td><td>3,5</td></tr>");
out.println("<tr><td>4,1</td><td>4,2</td><td>4,3</td><td>4,4</td><td>4,5</td></tr>");
out.println("<tr><td>5,1</td><td>5,2</td><td>5,3</td><td>5,4</td><td>5,5</td></tr>");
out.println("</table>");
out.close();
}
}

3.e3.html

<html>
<title>Welcome Page</title>
<body>
<form action="/e3.do">
<h1 align=center>J2ee Programing</h1><br>
<h3>Enter Your Name:<input type="text" name="name"></h3>
<h3>Enter Your Address:<input type="text" name="address"></h3>
<input type="submit" value="Click Me">
</form>
</body>
</html>

E3.java

import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;

public class e3 extends HttpServlet


{
String name=null;
String address=null;
public void service(HttpServletRequest req,HttpServletResponse res) throws IOException,ServletException
{
name=req.getParameter("name");
address=req.getParameter("address");
res.setContentType("text/html");
PrintWriter out=res.getWriter();
out.println("<h1 align=center> Java Programing</h1>");
out.println("<h3>Your Name :"+name+"</h3>");
out.println("<h3>Your Address :"+address+"</h3>");
out.close();
}
}

4. e4.java

import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
import java.util.*;
public class e4 extends HttpServlet
{
public void service(HttpServletRequest req,HttpServletResponse res) throws IOException,ServletException
{
res.setContentType("text/html");
PrintWriter out=res.getWriter();
// get the current session object, create one if necessary
HttpSession session=req.getSession(true);
// Increment the hit count for this page, the value is saved
// in this clients session under the name"tracker.count"
Integer count=(Integer)session.getValue("tracker.count");
if(count==null)
count=new Integer(1);
else
count=new Integer(count.intValue()+1);
session.putValue("tracker.count",count);
out.println("<html><title>Session Counts</title><body>");
out.println("<h2>Current Date And Time:"+new Date();+"</h2>");
out.println("<br><h3>The servlet has been"+count+((count.intVAlue()==1)?"time":"Times")+"accessed
since loaded<h3>");
out.println("</body></html>
out.close();
}
}

5.e5.html
<html>
<title>Welcome Page</title>
<body>
<form method="post" action="/inter.do">
<h1 align=center>Inter Servlet Communication</h1><br>
<h3>Enter Your Name:<input type="text" name="name"></h3>
<input type="submit" value="Click Me">
</form>
</body>
</html>

E5.java
import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
public class e5_1 extends HttpServlet
{
public void doPost(HttpServletRequest req,HttpServletResponse res) throws IOException,ServletException
{
String msg=null;
String name=req.getParameter("name");
msg="Hi "+name+", Welcome to Servlet Programming";
res.setContentType("text/html");
PrintWriter out=res.getWriter();
out.println("<br><h3>"+msg+" From First Servlet</h3><br>");
RequestDispatcher rd=req.getRequestDispatcher("e5_2.class");
rd.forward(req,res);
out.close();
}
}

import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;

public class e5_2 extends HttpServlet


{
public void doPost(HttpServletRequest req,HttpServletResponse res) throws IOException,ServletException
{
String msg=null;
String name=req.getParameter("name");
msg="Hi "+name+", Welcome to Servlet Programming";
res.setContentType("text/html");
PrintWriter out=res.getWriter();
out.println("<br><h3>"+msg+" From Second Servlet</h3><br>");
out.close();
}
}
6. e6.html

<html>
<title>Welcome Page</title>
<body>
<form action="/e6.do">
<h1 align=center>J2ee Programing</h1><br>
<h3>Enter Your Name:<input type="text" name="name"></h3>
<h3>Enter Your Address:<input type="text" name="address"></h3>
<input type="submit" value="Click Me">
</form>
</body>
</html>
E6.java
import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;

public class e6 extends HttpServlet


{
String sname=null;
int sport;
public void service(HttpServletRequest req,HttpServletResponse res) throws IOException,ServletException
{
sname=req.getServerName();
sport=req.getServerPort();
res.setContentType("text/html");
PrintWriter out=res.getWriter();
out.println("<h1 align=center> J2ee Programing</h1>");
out.println("<h2>Server Information</h2><br>");
out.println("<h3>Server Name :"+sname+"</h3>");
out.println("<h3>Server Port :"+sport+"</h3>");
out.close();
}
}

7. e7.html

<html>
<title>Welcome Page</title>
<body>
<form action="/e7.do">
<h1 align=center>J2ee Programing</h1><br>
<h3>Enter Your Roll Number:<input type="text" name="sno"></h3>
<input type="submit" value="Click Me">
</form>
</body>
</html>

E7.java

import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;

public class e7 extends HttpServlet


{
int sno;
Connection con=null;
Statement st=null;
public void service(HttpServletRequest req,HttpServletResponse res) throws IOException,ServletException
{
sno=req.getParameter("sno");
res.setContentType("text/html");
PrintWriter out=res.getWriter();
try
{
Class.forName("oracle.jdbc.driver.OracleDriver");
con=DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:orcl","scott","tiger");
st=con.createStatement();
String sq="select * from student where sno="+sno;
ResultSet rs=st.executeQuery(sq);
if(rs.next())
{
out.println("<h1 align=center> J2EE Programing</h1>");
out.println("<br><h3>Student Information</h3>");
out.println("<br>Student Number"+sno);
out.println("<br>Student Name :"+rs.getString(2);
out.println("<br>Student Address :"+rs.getString(3);
out.println("<br>Student Email Id :"+rs.getString(4);
out.println("<br>Program of study :"+rs.getString(5);
out.println("<br>Year of Admission :"+rs.getDate(6);
}
else
out.println("<br>Invalid Student Number Or Student doesn't Exist");
}
catch(Exception e)
{
out.println(e);
}
finally()
{
st.close();
con.close();
}
out.close();
}
}

8. e8.html

<html>
<title>Q3</title>
<body>
<form action="valid.do" method="GET">
<center>
<h1>Login here</h1>
<br>
<table border=0>
<tr><td>Enter User Name:</td><td><input type=text name="user"></td></tr>
<tr><td>Enter password:</td><td><input type=password name="password"></td></tr>
<tr><td><input type=submit value="Login"></td><td><input type=reset value="Reset"></td><tr>
</table>
</center>
</form>
</body>
</html>
E8.java

import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;

public class e8 extends HttpServlet


{
protected void doGet(HttpServletRequest req,HttpServletResponse res) throws ServletException, IOException
{
String user=req.getParameter("user");
String pass=req.getParameter("password");
res.setContentType("text/html");
PrintWriter out=res.getWriter();
if(user.equals("root") && pass.equals("root"))
{
RequestDispatcher rd=req.getRequestDispatcher("/e7.html");
rd.forward(req,res);
}
else
{
out.println("<html><body>");
out.println("<h1>Invalid User Name Password</h1>");
out.println("</body></html>");
}
out.close();
}
}

9. E9.jsp

import java.io.*;
import java.sql.*;
import javax.servlet.*;
import javax.servlet.http.*;

public class ses4q9 extends HttpServlet


{
public void doGet(HttpServletRequest request,HttpServletResponse response)
throws IOException, ServletException
{
response.setContentType("text/html");
PrintWriter out=response.getWriter();
out.println("<html><head><title>registration page</title></head><body>");
out.println("You are required to register first to get our services.<br>");
out.println("<table align='center'><form method='post' name=f action='ses4q9'>");
out.println("<tr><td>Name: &nbsp;&nbsp;</td><td><input type='text'
name='uname'></td></tr>");
out.println("<tr><td>Password: &nbsp;&nbsp;</td><td><input type='password'
name='upass'></td></tr>");
out.println("<tr><td><input type='submit' name='login' value='login'></td></tr>");
out.println("</form></table>");
out.println("<tr><td><a href='ses4q9a'>register</a></td></tr>");
out.println("</body></html>");
}

public void doPost(HttpServletRequest request,HttpServletResponse response)throws


IOException,ServletException
{
response.setContentType("text/html");
PrintWriter out=response.getWriter();
String id=request.getParameter("uname");
String pp=request.getParameter("upass");

out.println("<html><head><title>ses4q9</title></head><body>");
Connection con=null;
Statement stat=null,s=null;
ResultSet rs=null;
String chk_user="select * from users where user_id='"+id+"' and password='"+pp+"'";
String sql="select b.* from books b,categories c where b.category_id=c.category_id and
c.category_id=2";

try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
con=DriverManager.getConnection("jdbc:odbc:jspdatabase");
stat=con.createStatement();
rs=stat.executeQuery(chk_user);
if(rs.next())
{
String user = rs.getString(1);
String pass = rs.getString(2);

if((user.equals(id) && pass.equals(pp)))


{
HttpSession session=request.getSession(true);
String sid=session.getId();
out.println(sid);
session.setAttribute("session",sid);
session.setAttribute("UserId", id);
out.println("<TD>Welcome"+id+"</TD>");
out.println("<font size=5><center><b>WELCOME TO
THE COMPUTER WORLD</b><hr width=50%></center>");
out.println("<CENTER><TABLE BGCOLOR='gray'
BORDER='1'><TR>");

out.println("<TH>&nbsp;ISBN&nbsp;&nbsp;</TH><TH>&nbsp;TITLE&nbsp;&nbsp;</
TH><TH>&nbsp;&nbsp;AUTHOR&nbsp;&nbsp;</TH><TH>&nbsp;&nbsp;PRICE&nbsp;</TH>");

out.println("<TH>&nbsp;&nbsp;&nbsp;YEAR&nbsp;</TH><TH>&nbsp;&nbsp;&nbsp;PUBLISHER&nbsp;
</TH></TR>");

rs=stat.executeQuery(sql);
while(rs.next())
{
out.println("<TR>");
int ISBN=rs.getInt(1);
out.println("<TD>"+ISBN+"</TD>");
String TITLE=rs.getString(2);
out.println("<TD>"+TITLE+"</TD>");
String AUTHOR=rs.getString(3);
out.println("<TD>"+AUTHOR+"</TD>");
int PRICE=rs.getInt(4);
out.println("<TD>"+PRICE+"</TD>");
int catid=rs.getInt(5);
int YEAR=rs.getInt(6);
out.println("<TD>"+YEAR+"</TD>");
String PUBLISHER=rs.getString(7);
out.println("<TD>"+PUBLISHER+"</TD>");
out.println("<TD><A HREF='ses4q9b?
ISBN="+ISBN+"&&TITLE="+TITLE+"&&AUTHOR="+AUTHOR+"&&PUBLISHER="+PUBLISHER+"
&&YEAR="+YEAR+"&&PRICE="+PRICE+"'>Order Now</A></TD>");
out.println("</TR>");
}
}
}
else
{
out.println("you need to be registered first");
out.println("<a href='ses4q9a'>registration page</a>");

}
catch(Exception e)
{
System.out.println(e);
}
finally
{
try{
if(rs!=null)
rs.close();
if(stat!=null)
stat.close();
if(con!=null)
con.close();
}
catch(Exception e)
{
System.out.println(e);
}
}
out.println("</TABLE></CENTER></font></BODY></HTML>");
}

}
ses4q9a.jsp
import java.io.*;
import java.sql.*;
import javax.servlet.*;
import javax.servlet.http.*;

public class ses4q9a extends HttpServlet


{
public void doGet(HttpServletRequest request,HttpServletResponse response)
throws IOException, ServletException
{
response.setContentType("text/html");
PrintWriter out=response.getWriter();
out.println("<html><head><title>registration page</title></head><body>");
out.println("You are required to register first to get our services.<br>");
out.println("<table align='center'><form method='post' name=f action='ses4q9a'>");
out.println("<tr><td>Name: &nbsp;&nbsp;</td><td><input type='text'
name='uname'></td></tr>");
out.println("<tr><td>Password: &nbsp;&nbsp;</td><td><input type='password'
name='upass'></td></tr>");
out.println("<tr><td><input type='submit' name='sub' value='register'></td></tr>");
out.println("</form></table>");
out.println("</body></html>");
}

public void doPost(HttpServletRequest request,HttpServletResponse response)throws


IOException,ServletException
{
response.setContentType("text/html");
PrintWriter out=response.getWriter();
String id=request.getParameter("uname");
String pp=request.getParameter("upass");

out.println("<html><head><title>ses4q9</title></head><body>");
out.println("<font size=5><center><b>WELCOME TO THE COMPUTER
WORLD</b><hr width=50%></center>");
Connection con=null;
Statement stat=null,s=null;
ResultSet rs=null;
String chk_user="select user_id,password from users where user_id='"+id+"' and
password='"+pp+"'";
String ins_val="insert into users values('"+id+"','"+pp+"')";
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
con=DriverManager.getConnection("jdbc:odbc:jspdatabase");
stat=con.createStatement();
rs=stat.executeQuery(chk_user);
if(rs.next())
{
String user = rs.getString(1);
String pass = rs.getString(2);
if(user.equals(id) && pass.equals(pp))
{
out.println(id+" user already exists. try another or return to
<a href='ses4q9'>login</a> page");
}
}
else
{
s=con.createStatement();
s.executeUpdate(ins_val);
out.println("successfully registered");
out.println("<a href='ses4q9'>login</a>");
}

}
catch(Exception e)
{
System.out.println(e);
}
finally
{
try{
if(rs!=null)
rs.close();
if(stat!=null)
stat.close();
if(s!=null)
s.close();
if(con!=null)
con.close();
}
catch(Exception e)
{
System.out.println("hi1"+e);
}
}
out.println("</TABLE></CENTER></font></BODY></HTML>");
}
}
ses4q9b.jsp
import java.io.*;
import java.sql.*;
import javax.servlet.*;
import javax.servlet.http.*;

public class ses4q9b extends HttpServlet


{
public void doGet(HttpServletRequest request,HttpServletResponse response)throws
IOException,ServletException
{
response.setContentType("text/html");
PrintWriter out=response.getWriter();
HttpSession session=request.getSession(false);
String ISBN=request.getParameter("ISBN");
String YEAR=request.getParameter("YEAR");
String PRICE=request.getParameter("PRICE");
String TITLE=request.getParameter("TITLE");
String AUTHOR=request.getParameter("AUTHOR");
String PUBLISHER=request.getParameter("PUBLISHER");
String sid=(String)session.getAttribute("session");
session.setAttribute("bookid",ISBN);
if(sid!=null)
{
out.println("<html><head><title>order page</title></head><body>");
out.println("you opted to place order for :"+TITLE+" of "+PUBLISHER +" publications for rs:
"+PRICE);
out.println("<CENTER><form name='orderform' method='post'><table border='0'>");
out.println("<tr><td>Name :</td><td><input type='text' name='cname'></td></tr>");
out.println("<tr><td>Address :</td><td><input type='text' name='add'></td></tr>");
out.println("<tr><td>Quantity :</td><td><input type='text' name='qty'></td></tr>");
out.println("<tr><td><INPUT TYPE='submit' value='place order'></td></tr>");
out.println("</table></form></CENTER></body></html>");
}
else
{
response.sendRedirect("ses4q9");
}
}

public void doPost(HttpServletRequest request,HttpServletResponse response)throws


IOException,ServletException
{
response.setContentType("text/html");
PrintWriter out=response.getWriter();
HttpSession session=request.getSession(false);
String bookid=(String)session.getAttribute("bookid");
String sid=(String)session.getAttribute("session");
//out.println(sid);
String id=request.getParameter("cname");
String pp=request.getParameter("add");
String qt=(String)request.getParameter("qty");
if(sid!=null)
{
out.println("<html><head><title>ses4q9</title></head><body>");
out.println("<font size=5><center><b>WELCOME TO THE COMPUTER
WORLD</b><hr width=50%></center>");
Connection con=null;
Statement stat=null,s=null;
ResultSet rs=null;
String ins_val="insert into order_detail(user_id,book_id,quantity,address)
values('"+id+"',"+bookid+",'"+qt+"','"+pp+"')";
//String ins_val="insert into order_detail values(1,'vivek',2,2,'delhi')";
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
con=DriverManager.getConnection("jdbc:odbc:jspdatabase");
s=con.createStatement();
s.executeUpdate(ins_val);
out.println("successfully placed order and we will deliver you soon");
out.println("<a href='ses4q9c'>logout</a>");
}
catch(Exception e)
{
System.out.println(e);
}
finally
{
try{
if(rs!=null)
rs.close();
if(s!=null)
s.close();
if(con!=null)
con.close();
}
catch(Exception e)
{
System.out.println(e);
}
}
out.println("</TABLE></CENTER></font></BODY></HTML>");
}
else
{
response.sendRedirect("ses4q9");
}
}
}
sec4q9c.jsp
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;

public class ses4q9c extends HttpServlet


{
int count=1;
public void doGet(HttpServletRequest request,HttpServletResponse response)throws
IOException,ServletException
{
response.setContentType("text/html");
PrintWriter out=response.getWriter();
HttpSession session=request.getSession(false);
String sid=(String)session.getAttribute("session");
//out.println("old"+sid);
session.setAttribute("session",null);
String sids=(String)session.getAttribute("session");
//out.println("new"+sids);
if(sids==null)
{
response.sendRedirect("ses4q9");
}
}

10. E10.jsp

<html>
<head><title>JSP programming</title><head>
<body color=blue>
<h1>
<%
out.print("Welcome to JSP World. The Time Now is ");
out.println(new java.util.Date());
%>
</h1>
</body>
</html>

11. e11.jsp

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


<html>
<head><title>JSP programming</title><head>
<body color=blue>
<h1>
<%
if(session.isNew())
{
Random r=new Random();
long no=r.nextLong();
String rno=new String("");
rno=rno+no;
session.setAttribute("randno",rno);
}
out.println("No Is :"+session.getAttribute("randno"));
%>
</h1>
</body>
</html>

12.e12.jsp

<HTML>
<HEAD>
<TITLE>ses5q12</TITLE>
</HEAD>
<BODY>
<H2><CENTER>WELCOME TO THE SYSTEM.<br><br><br></H2>
<TABLE BGCOLOR="#AABBFF" BORDER="0" align="center">
<TR><TD>JAVA VERSION</TD><TD> :<%= System.getProperty("java.version") %></TD></TR>
<TR><TD>JAVA HOME</TD><TD> :<%= System.getProperty("java.home") %></TD></TD>
<TR><TD> OS NAME </TD><TD>:<%= System.getProperty("os.name") %></TD></TR>
<TR><TD> USER NAME</TD><TD> :<%= System.getProperty("user.name") %></TD></TR>
<TR><TD> USER HOME </TD><TD>:<%= System.getProperty("user.home") %></TD></TR>
<TR><TD>USER DIRECTRY</TD><TD> :<%= System.getProperty("user.dir") %></TD></TR>
</TABLE>
</BODY>
</HTML>

13. e13.jsp

<html>
<head><title>JSP programming</title><head>
<body color=blue>
<h1>
<%
Boolen b=true;
do
{
if(b)
{
out.println("Now executing true value and Using jsp:include");
%>
<jsp:include page="welcome.jsp">
<jsp:param name="name" value="Dude"/>
</jsp:include>
<%
b=false;
}
else
{
out.println("Now executing false value and Using jsp:forward");
%>
<jsp:forward page="welcome.jsp">
<jsp:param name="name" value="Dude"/>
</jsp:forward>
<%
b=true;
}
}while(!b);
%>
</h1>
</body>
</html>

14. e14.jsp

<html>
<head><title>JSP programming</title><head>
<body color=blue>
<h1>
<%
out.print("Welcome to JSP Programming");
%>
</h1>
<jsp:forward page="e14">
<jsp:param name="name" value="Manyam"/>
<jsp:param name="address" value="Bangalore"/>
<jsp:param name="dob" value="10-apr-2000"/>
</jsp:forward>
</body>
</html>

E14.java

import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;

public class e14 extends HttpServlet


{
String name=null;
String address=null;
public void service(HttpServletRequest req,HttpServletResponse res) throws IOException,ServletException
{
name=req.getParameter("name");
address=req.getParameter("address");
dob=req.getParameter("dob");
res.setContentType("text/html");
PrintWriter out=res.getWriter();
out.println("<h1 align=center> Java Programing</h1>");
out.println("<h3>Your Name :"+name+"</h3>");
out.println("<h3>Your Address :"+address+"</h3>");
out.println("<h3>Your Date of Birth :"+dob+"</h3>");
out.close();
}
}

15. e15.html

<html>
<title>java programming</title>
<body>
<form action="e15.jsp">
<h1 align=center>Customer Form</h1><br>
<h3>Enter Customer Name:<input type="text" name="name"></h3>
<h3>Enter Customer Address:<input type="text" name="address"></h3>
<h3>Enter Customer Mobile No:<input type="text" name="mobileno"></h3>
<input type="submit" value="Click Me">
</form>
</body>
</html>

E15.jsp
<%@ page import="java.sql.*"%>
<%!
Connection con=null;
PreparedStatement ps=null;
String name,address,mobileno;
public Connection getCon()
{
try
{
Class.forName("oracle.jdbc.driver.OracleDriver");
con=DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:orcl","scott","tiger");
}
catch(Exception e)
{
System.out.println(e);
}
return con;
}

%>
<html><body>
<%
try
{
name=req.getParameter("name");
address=reg.getParameter("address");
mobileno=reg.getParameter("mobileno");
con=getCon();
ps=con.prepareStatement("select * from customer where cname=? and address=? and phone=?");
ps.setString(1,name);
ps.setString(2,address);
ps.setString(3,mobileno);
ResultSet rs=ps.executeQuery();
if(rs.next())
msg="Valid Customer";
else
msg="Invalid Customer";

}
catch(Exception e)
{
e.printStackTrace();
}
finally
{
try
{
if(ps!=null)
ps.close();
if(con!=null)
con.close();
}
catch(Exception e)
{
System.out.println(e);
}
}
%>
<h1><%=msg %></h1>
</body></html>

16. e16.jsp

<html>
<head><title>JSP programming</title><head>
<body color=blue>
<h3>Including the Program written in Exercise9</h3>
<hr>
<jsp:include page="e9.html">
</jsp:include>
<hr>
</body>
</html>

17. e17.jsp

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


<%!
Connection con=null;
PreparedStatement ps=null;
public Connection getCon()
{
try
{
Class.forName("oracle.jdbc.driver.OracleDriver");
con=DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:orcl","scott","tiger");
}
catch(Exception e)
{
System.out.println(e);
}
return con;
}
%>
<html><body>
<h1>Student who Born after 1985 are </h1>
<table align=center>
<tr><th>Sudent Name</th><th>address<th>M/tr>
<%
try
{
con=getCon();
ps=con.prepareStatement("select * from student where year(dob)>1985");
ResultSet rs=ps.executeQuery();
while(rs.next())
{
%>
<tr><td><%=ps.getString(2)%></td>
<td><%=ps.getString(5)%>,<%=ps.getString(6)%>,<%=ps.getString(7)%></td>
</tr>
<%
}
%>
<%
}
catch(Exception e)
{
e.printStackTrace();
}
finally
{
try
{
if(ps!=null)
ps.close();
if(con!=null)
con.close();
}
catch(Exception e)
{
System.out.println(e);
}
}
%>
</table>
</body></html>

18. e18.jsp

<html>
<head><title>JSP programming</title><head>
<body color=blue>
<hr>
<h1> Displaying Personnel web page from JSP<h1>
<hr>
<jsp:include page="e18.html">
</body>
</html>

19. e19.jsp
<%@ page import="java.sql.*"%>
<%!
Connection con=null;
PreparedStatement ps=null;
public Connection getCon()
{
try
{
Class.forName("oracle.jdbc.driver.OracleDriver");
con=DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:orcl","scott","tiger");
}
catch(Exception e)
{
System.out.println(e);
}
return con;
}
%>
<html>
<head><title>JSP Programming</title></head>
<body text=blue>
<h1 align=center>Product Information of Electronics Goods</h1>
<form name="insert" action="/insert.do">
<hr><font color=red size=5><center>Insert Form</font></center><br><hr>
<table align=center>
<tr><td>Item No</td><td><input type="text" name="ino"></td></tr>
<tr><td>Item Name</td><td><input type="text" name="iname"></td></tr>
<tr><td>Item Price</td><td><input type="text" name="iprice"></td></tr>
<tr><td>Item Warantee</td><td><input type="text" name="iwarant"></td></tr>
<tr><td>Item Color</td><td><input type="text" name="icolor"></td></tr>
<tr><td>Item Company</td><td><input type="text" name="icompany"></td></tr>
<tr><td colspan=2 align=center><input type=submit value="Insert in to Database"></td></tr>
</table>
</form>
<form name="dispaly" action="display.jsp">
<hr><font color=red size=5><center>Display Form</center></font><br><hr>
<h3 align=center>Select an Item To Display Details
<select name="item">
<%
try
{
con=getCon();
ps=con.prepareStatement("Select itemno from product");
ResultSet rs=ps.executeQuery();
while(rs.next())
{
String item=rs.getString(1);
%>
<option value="<%item%>"><%item%></option>
<%
}
%>
</select><br>
<%
}
catch(Exception e)
{
out.println(e);
}
finally
{
try
{
if(ps!=null)
ps.close();
if(con!=null)
con.close();
}
catch(Exception e)
{
System.out.println(e);
}
}
%>
<input type=submit value="Display"></h3>
</form>
</body>
</html>

E19.java
import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;

public class e19 extends HttpServlet


{
int sno;
Connection con=null;
PreparedStatement ps=null;
public void service(HttpServletRequest req,HttpServletResponse res) throws IOException,ServletException
{
sno=req.getParameter("sno");
res.setContentType("text/html");
PrintWriter out=res.getWriter();
ino=req.getParameter("ino");
iname=req.getParameter("iname");
iprice=req.getParameter("iprice");
warant=req.getParameter("iwarant");
color=req.getParameter("color");
company=req.getParameter("company");
try
{
Class.forName("oracle.jdbc.driver.OracleDriver");
con=DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:orcl","scott","tiger");
ps=con.prepareStatement("insert into product values(?,?,?,?,?,?)");
ps.setString(1,ino);
ps.setString(2,iname);
ps.setString(3,iprice);
ps.setString(4,warant);
ps.setString(5,color);
ps.setString(6,company);
int x=ps.executeUpdate();
if(x==1)
{
out.println("<h1 align=center>J2EE Programing</h1>");
out.println("<br><h3>Product Information has been inserted</h3>");
}
else
out.println("<br>Product Information not inserted");
}
catch(Exception e)
{
out.println(e);
}
finally()
{
try
{
ps.close();
con.close();
}
catch(Exception e)
{out.println(e);}
}
out.close();
}
}

E19_1.jsp

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


<%!
Connection con=null;
PreparedStatement ps=null;
public Connection getCon()
{
try
{
Class.forName("oracle.jdbc.driver.OracleDriver");
con=DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:orcl","scott","tiger");
}
catch(Exception e)
{
System.out.println(e);
}
return con;
}
%>
<html><body>
<h1>Product Information </h1>
<table align=center>
<%
try
{
con=getCon();
String item=request.getParameter("ino");
ps=con.prepareStatement("select * from product where itemno=?");
ps.setString(1,item);
ResultSet rs=ps.executeQuery();
if(rs.next())
{
%>
<tr><td>Item No</td><td><%=ps.getString(1)%></td></tr>
<tr><td>Item name</td><td><%=ps.getString(1)%></td></tr>
<tr><td>Item Price</td><td><%=ps.getString(1)%></td></tr>
<tr><td>Item Warantee</td><td><%=ps.getString(1)%></td></tr>
<tr><td>Item Color</td><td><%=ps.getString(1)%></td></tr>
<tr><td>Item Company</td><td><%=ps.getString(1)%></td></tr>

<%}%>
<%
}
catch(Exception e)
{
e.printStackTrace();
}
finally
{
try
{
if(ps!=null)
ps.close();
if(con!=null)
con.close();
}
catch(Exception e)
{
System.out.println(e);
}
}
%>
</table>
</body></html>

20. e20.xml
<?xml version="1.0" encoding="ISO-8859-1"?>
<note>
<to>Ramu</to>
<from>Deenu</from>
<heading>Festival Whishes</heading>
<body>May God give all the happiness to you and your family and
i am wishing u the best wishes</body>
<closing>Best Wishes</closing>
<signature>Ramu</signature>
</note>

21. e21.xml
<?xml version="1.0" encoding="ISO-8859-1"?>
<books>
<book>
<title>My First Servlet</title>
<unit1>
<name>Introduction to servlet</name>
<chapters>
<ch1>* What is Servlet</ch1>
<ch2>* what are the advantage of servlet</ch2>
</chapters>
</unit1>
<unit2>
<name>Servlet Life Cycle</name>
<chapters>
<ch1>* Servlet Initialization</ch1>
<ch2>* Servlet Reloading</ch2>
<ch3>* Destroying a Servlet</ch3>
</chapters>
</unit2>
</book>
</books>

22.e22.xml
<?xml version="1.0" ?>
<!-- A Comment -->
<Name xml:space="preserve">white space problem</Name>

23. e23.xml
<?xml version="1.0" encoding="ISO-8859-1"?>
<students-subjects>
<student-subject>
<subject>Visual Basic Programming</subject>
<qualification>B.Tech</qualification>
<student1>Mohan</student1>
<student2>Naveen</student2>
</student-subject>
<student-subject>
<subject>Java Programming</subject>
<qualification>M.Tech</qualification>
<student1>Robert John</student1>
<student2>Sudhansh</student2>
</student-subject>
<student-subject>
<subject>ASP Programming</subject>
<qualification>M.Sc</qualification>
<student1>Neeta</student1>
<student2>Ravi</student2>
</student-subject>
</students-subjects>

25. e25.html
<html>
<title>Welcome Page</title>
<body>
<form action="e25.jsp">
<h1 align=center>Table specification</h1><br>
<h3>Enter No Of Rows<input type="text" name="row"></h3>
<h3>Enter No Of Columns<input type="text" name="col"></h3>
<input type="submit" value="Click Me">
</form>
</body>
</html>

E25.jsp
<html>
<head><title>Displaying Table</title></head>
<body text=blue>
<h1>Displaying Table </h1>
<table align=center border=1>
<%
try
{
int col=request.getParameter("col");
int row=request.getParameter("row");
for(int i=1;i<=row;i++)
{
%>
<tr>
<%
for(int j=1;j<=col;j++)
{
%>
<td> </td>
<%
}
</tr>
}
%>
<%
}
catch(Exception e)
{
e.printStackTrace();
}
%>
</table>
</body></html>
Sec10e26.jsp
<%@page import="java.sql.*"%>
<html>
<head>
<style>
a
{text-decoration:none}
</style>
<script language="javascript">
<!--
function callme(sel)
{
document.comp.a.value=sel.value;
}

function checkEmail(form)
{
if(isNaN(form.can_pack.value))
{
alert("enter the numeric package");
}
else if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(form.can_add.value))
{
form.Submit();
}
else
{
alert("Invalid E-mail Address! Please re-enter.")
//return false;
}

function showaddclient()
{
document.getElementById("client").style.display="inline";
document.getElementById("candidates").style.display="none";
document.getElementById("search").style.display="none";
document.getElementById("fieldwise").style.display="none";
document.st.n.value="showclient";
}

function showaddcandidate()
{
document.getElementById("candidates").style.display="inline";
document.getElementById("client").style.display="none";
document.getElementById("search").style.display="none";
document.getElementById("fieldwise").style.display="none";
document.st.n.value="showcandidate";
}

function showaddsearch()
{
document.getElementById("candidates").style.display="none";
document.getElementById("client").style.display="none";
document.getElementById("search").style.display="inline";
document.getElementById("fieldwise").style.display="none";
document.st.n.value="showsearch";
}

function showfieldwise()
{
document.getElementById("candidates").style.display="none";
document.getElementById("client").style.display="none";
document.getElementById("search").style.display="none";
document.getElementById("fieldwise").style.display="inline";
document.st.n.value="showfield";
}

function hideclient()
{
if(document.st.n.value=="showclient")
{
document.getElementById("client").style.display="inline";
document.getElementById("candidates").style.display="none";
document.getElementById("search").style.display="none";
document.getElementById("fieldwise").style.display="none";
}
else if(document.st.n.value=="showcandidate")
{
document.getElementById("candidates").style.display="inline";
document.getElementById("client").style.display="none";
document.getElementById("search").style.display="none";
document.getElementById("fieldwise").style.display="none";
}
else if(document.st.n.value=="showsearch")
{
document.getElementById("candidates").style.display="none";
document.getElementById("client").style.display="none";
document.getElementById("search").style.display="inline";
document.getElementById("fieldwise").style.display="none";
}
else if(document.st.n.value=="showfield")
{
document.getElementById("candidates").style.display="none";
document.getElementById("client").style.display="none";
document.getElementById("search").style.display="none";
document.getElementById("fieldwise").style.display="inline";
}
else
{
document.getElementById("client").style.display="none";
document.getElementById("candidates").style.display="none";
document.getElementById("search").style.display="none";
document.getElementById("fieldwise").style.display="none";
}
}
-->
</script>
<title>recruitement agency</title>
<body onLoad="hideclient()">
<table border=1 width=100% height="100%"><tr>
<td height=20%>
<form name="st">
<input type="hidden" name="n">
</form>

<center><h1>welcome To Recruitement Agency</h1></center>


<font size=5>
<ol start=1>
<li><a href="javascript:onClick=showaddclient()">Add Clients</a></li>
<li><a href="javascript:onClick=showaddcandidate()">Add Candidate</a></li>
<li><a href="javascript:onClick=showaddsearch()">Search for jobs</a></li>
<li><a href="javascript:onClick=showfieldwise()">Search by jobs fileds</a></li>
</ol>
</font>
</td></tr>
<tr>
<td cellpadding=1 topmargin=0 valign="top" align="center">

<div id="client">
<pre>
Enter the Company Details
<form name="addclient">
Name: <input type="text" name="clt_name"><br>
Address: <input type="text" name="clt_add"><br>
Status: <input type="text" size=50 name="clt_status"><br>
Field: <input type="text" name="clt_field"><br>
Designation: <input type="text" name="clt_desig"><br>
Package_offer: <input type="text" name="clt_pack"><br>
Experience_requi:<input type="text" name="clt_ex"><br>

<input type="submit" name="st" value="store_information">


</pre>
</form>
<%
String stor=request.getParameter("st");
String cl_name=request.getParameter("clt_name");
String cl_add=request.getParameter("clt_add");
String cl_stat=request.getParameter("clt_status");
String cl_field=request.getParameter("clt_field");
String cl_desig=request.getParameter("clt_desig");
String cl_pack=request.getParameter("clt_pack");
String cl_ex=request.getParameter("clt_ex");
if(stor!=null)
{
%>
<script language="javascript">
<!--
document.st.n.value="showclient";
-->
</script>
<%
}

if(stor!=null)
{
Connection con=null;
Statement st3=null,st4=null,st5=null;
ResultSet rs1=null;

try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
con=DriverManager.getConnection("jdbc:odbc:jspdatabase");
st3=con.createStatement();
st4=con.createStatement();
st5=con.createStatement();
String ins_client="insert into companies(com_name,com_address,com_status)
values('"+cl_name+"','"+cl_add+"','"+cl_stat+"')";
int k=st3.executeUpdate(ins_client);
int idd=0;
if(k==1)
{
out.println("client specifications successfully added");
String getidd="select com_id from companies";
rs1=st4.executeQuery(getidd);
while(rs1.next())
{
idd=rs1.getInt(1);

String ins_client_specification="insert into


com_requirement(com_id,Field,Designation,Package,experience)
values("+idd+",'"+cl_field+"','"+cl_desig+"','"+cl_pack+"','"+cl_ex+"')";

int l=st5.executeUpdate(ins_client_specification);
if(l==1)
{
out.println("clients specifications entered successfully");
}
}
else
{
out.println("problem inserting the clients values");
}

}
catch(Exception e)
{
out.println("error inserting the clients"+e);
}

}
%>
</div>

<div id="candidates">
<pre>
Enter the Candidates Details
<form name="addcandidate" onSubmit="checkEmail(this);return false;">
Name: <input type="text" name="can_name"><br>
Email Address: <input type="text" name="can_add"><br>
Eligibility: <input type="text" name="can_el"><br>
Experience: <input type="text" name="can_ex"><br>
Post_required: <input type="text" name="can_post"><br>
Pack_required: <input type="text" name="can_pack"><br>

<input type="submit" name="stcan" value="store_information">


</pre>
</form>
<%
String store=request.getParameter("stcan");
String ca_name=request.getParameter("can_name");
String ca_add=request.getParameter("can_add");
String ca_el=request.getParameter("can_el");
String ca_ex=request.getParameter("can_ex");
String ca_post=request.getParameter("can_post");
String ca_pack=request.getParameter("can_pack");
if(store!=null)
{
%>
<script language="javascript">
<!--
document.st.n.value="showcandidate";
-->
</script>
<%
}

if(store!=null)
{
Connection con=null;
Statement st=null,st1=null,st2=null;
ResultSet rs=null;

try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
con=DriverManager.getConnection("jdbc:odbc:jspdatabase");
st=con.createStatement();
st1=con.createStatement();
st2=con.createStatement();
String ins_candidate="insert into candidates(candi_name,candi_address)
values('"+ca_name+"','"+ca_add+"')";
int j=st.executeUpdate(ins_candidate);
int id=0;
if(j==1)
{
out.println("client specifications successfully added");
String getid="select candi_id from candidates";
rs=st2.executeQuery(getid);
while(rs.next())
{
id=rs.getInt(1);

String ins_candidate_specification="insert into


joblist(candi_id,eligibity,experience,post_requirement,package_required)
values("+id+",'"+ca_el+"','"+ca_ex+"','"+ca_post+"',"+ca_pack+")";

int i=st1.executeUpdate(ins_candidate_specification);
if(i==1)
{
out.println("candidates specifications entered successfully");
}
}
else
{
out.println("problem inserting the values");
}

}
catch(Exception e)
{
out.println("error inserting the candidate"+e);
}

}
%>
</div>

<div id="search">
<form name="search">
<pre>
Enter the client id: <input type="text" name="clt_id">
<input type="submit" name="specifications" value="getStatus">

<%
String spec=request.getParameter("specifications");
String cc_id=request.getParameter("clt_id");
if(spec!=null)
{
%>
<script language="javascript">
<!--
document.st.n.value="showsearch";
-->
</script>
<%
}
if(spec!=null)
{
Connection con=null;
Statement st6=null;
ResultSet rs2=null,rs3=null;
String status=null;
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
con=DriverManager.getConnection("jdbc:odbc:jspdatabase");
st6=con.createStatement();
String getSpecification="select c.candi_id,c.candi_name,c.candi_address,c.job_status from
candidates c where c.candi_id="+cc_id+"";
rs2=st6.executeQuery(getSpecification);
if(rs2.next()==false)
{
out.println("client does not exists ");
}
else
{
//rs2=st6.executeQuery(getSpecification);
//if(rs2.next())
//{
out.println("client name: "+rs2.getString(2));
out.println("Email: "+rs2.getString(3));
status=rs2.getString(4);

if(status.equals("Not settled"))
{
out.println("job Status: <u>"+status+"</u><a href='../getjobs?
cc_id="+cc_id+"'>(click on it to get the job as per requirement )</a>");
}
else
{
out.println("This Candidate is already settled");
}
}
//}

}
catch(SQLException e)
{
out.println("problem retrieving the data"+e);
}
}
%>
</pre>
</form>
</div>

<div id="fieldwise">
Select the required field:<jsp:include page="../Readfields" flush="true">
<jsp:param name="filed" value="fieldname"/>
</jsp:include>
<%
String sub=request.getParameter("sub");
if(sub!=null)
{
%>
<script language="javascript">
<!--
document.st.n.value="showfield";
-->
</script>
<%
}
%>
</div>
</td>
</tr>
</table>
</body>
</head>
</html>

getcompanieslist.jsp
<%@page import="java.sql.*"%>
<html>
<head>
<title>recruitement agency</title>
<body>
Company Details
<%
String company=request.getParameter("list");
int companyid=Integer.parseInt(company);
Connection con=null;
Statement st=null;
ResultSet rs=null;

try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
con=DriverManager.getConnection("jdbc:odbc:jspdatabase");
st=con.createStatement();
String getcompany="select * from companies where com_id="+companyid+"";
rs=st.executeQuery(getcompany);
out.println("<table border=1 align=center>");
out.println("<tr><td>company id</td><td>company name</td><td>company
address</td><td>company status</td></tr>");
while(rs.next())
{
out.println("<tr>");
out.println("<td>"+rs.getInt(1)+"</td>");
out.println("<td>"+rs.getString(2)+"</td>");
out.println("<td>"+rs.getString(3)+"</td>");
out.println("<td>"+rs.getString(4)+"</td>");
out.println("</tr>");
}
out.println("</table>");
out.println("<a href='javascript:history.go(-1)'>back</a>");

}
catch(Exception e)
{
out.println("error inserting the candidate"+e);
}

%>
</body>
</head>
</html>

getjob.java
import java.io.*;
import java.sql.*;
import javax.servlet.*;
import javax.servlet.http.*;

public class getjobs extends HttpServlet


{
public void doGet(HttpServletRequest req,HttpServletResponse res)throws IOException,ServletException
{

res.setContentType("text/html");
PrintWriter out=res.getWriter();
out.println("<html><body>");
String From=req.getParameter("cc_id");
String re=null;
Connection con=null;
Statement st=null,st1=null;
ResultSet rs=null,rs1=null;
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
con=DriverManager.getConnection("jdbc:odbc:jspdatabase");
st=con.createStatement();
st1=con.createStatement();
String require="select post_requirement from joblist where candi_id="+From+"";
rs1=st1.executeQuery(require);
while(rs1.next())
{
re=rs1.getString("post_requirement");
}
String[] items = re.split(" ");

out.println("Jobs Matching With the Required Specification for Client id"+From+"");

String getSpecification="select * from com_requirement where Designation LIKE


'%"+items[0]+"%'";
rs=st.executeQuery(getSpecification);
out.println("<table align=center border=1>");
out.println("<tr>");
out.println("<td>company_id </td><td>Field Of Work </td><td>Designation</td><td>Package
Offered</td><td>Experience required</td>");
out.println("</tr>");

while(rs.next())
{
out.println("<tr>");
int list=rs.getInt(1);
out.println("<td><a href=ses10/getcompanieslist.jsp?list="+list+">"+list+"</a></td>");
out.println("<td>"+rs.getString(2)+"</td>");
out.println("<td>"+rs.getString(3)+"</td>");
out.println("<td>"+rs.getInt(4)+"</td>");
out.println("<td>"+rs.getString(5)+"</td>");
out.println("</tr>");
}
out.println("</table>");
}
catch(Exception e)
{
out.println("problem finding the jobs"+e);
}
finally
{
try
{
if(st!=null)
{
st.close();
}
else if(st1!=null)
{
st1.close();
}
else if(rs!=null)
{
rs.close();
}
else if(rs1!=null)
{
rs1.close();
}
}
catch (Exception e)
{
out.println("problem closing database connection"+e);
}
}
out.println("</body></html>");
}

readfields.java
import java.io.*;
import java.sql.*;
import javax.servlet.*;
import javax.servlet.http.*;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;

public class Readfields extends HttpServlet


{
public void doGet(HttpServletRequest req,HttpServletResponse res)throws IOException,ServletException
{

res.setContentType("text/html");
PrintWriter out=res.getWriter();
out.println("<html><body>");
try
{
File file = new File("C:/Tomcat5.5/apache-tomcat-5.5.27/webapps/viveklab/ses10/companies.xml");
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
DocumentBuilder db = dbf.newDocumentBuilder();
Document doc = db.parse(file);
doc.getDocumentElement().normalize();
NodeList nodeLst=null,nodeLst1=null;
String field=req.getParameter("filed");
out.println("<form name=comp method='post'>");
out.println("<input type=hidden name=a>");
nodeLst= doc.getElementsByTagName(field);
out.println("<select name=From onChange='callme(this)'>");
for (int s = 0; s < nodeLst.getLength(); s++)
{
Node fstNode = nodeLst.item(s);
if (fstNode.getNodeType() == Node.ELEMENT_NODE)
{
Element fstElmnt = (Element) fstNode;
NodeList fstNmElmntLst = fstElmnt.getElementsByTagName("name");
Element fstNmElmnt = (Element) fstNmElmntLst.item(0);
NodeList fstNm = fstNmElmnt.getChildNodes();
String getval=((Node) fstNm.item(0)).getNodeValue();
out.println("<option value="+getval+">");
out.println(getval);
out.println("</option>");
}
}
out.println("</select>");
out.println("<input type=submit name=sub value=getCompanies>");
out.println("</form>");
}
catch (Exception e) {
e.printStackTrace();
}

out.println("</body></html>");
}

public void doPost(HttpServletRequest req,HttpServletResponse res)throws IOException,ServletException


{

res.setContentType("text/html");
PrintWriter out=res.getWriter();
out.println("<html><body>");
Connection con=null;
Statement st6=null;
ResultSet rs2=null;
String status=null;
String rr=req.getParameter("a");
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
con=DriverManager.getConnection("jdbc:odbc:jspdatabase");
st6=con.createStatement();
String getSpecification="select * from com_requirement where Field LIKE '%"+rr+"%'";
rs2=st6.executeQuery(getSpecification);

out.println("<table align=center border=1>");


out.println("<tr>");
out.println("<td>company_id </td><td>Field Of Work </td><td>Designation</td><td>Package
Offered</td><td>Experience required</td>");
out.println("</tr>");

while(rs2.next())
{
out.println("<tr>");
int list=rs2.getInt(1);
out.println("<td><a
href=../ses10/getcompanieslist.jsp?list="+list+">"+list+"</a></td>");
out.println("<td>"+rs2.getString(2)+"</td>");
out.println("<td>"+rs2.getString(3)+"</td>");
out.println("<td>"+rs2.getInt(4)+"</td>");
out.println("<td>"+rs2.getString(5)+"</td>");
out.println("</tr>");
}
out.println("</table>");
out.println("<a href='javascript:history.go(-1)'>back</a>");

}
catch(Exception e)
{
out.println("problem retrieving the data"+e);
}
}
}

companies.xml
<?xml version="1.0"?>
<Fields>
<fieldname>
<name>steel industries</name>
</fieldname>
<fieldname>
<name>home appliances</name>
</fieldname>
<fieldname>
<name>mobile repairing</name>
</fieldname>
<fieldname>
<name>accounting</name>
</fieldname>
<fieldname>
<name>electricity_development</name>
</fieldname>
<fieldname>
<name>godown management</name>
</fieldname>
<fieldname>
<name>sales</name>
</fieldname>
<fieldname>
<name>billing</name>
</fieldname>
<fieldname>
<name>inventory</name>
</fieldname>
<fieldname>
<name>site development</name>
</fieldname>
<fieldname>
<name>site management</name>
</fieldname>
<fieldname>
<name>softwares</name>
</fieldname>
<fieldname>
<name>online projects</name>
</fieldname>
<fieldname>
<name>weaving</name>
</fieldname>
</Fields>

You might also like