lab record 51part 1
TRANSCRIPT
-
7/29/2019 Lab Record 51part 1
1/46
Advanced
Internet
Technologies
-
7/29/2019 Lab Record 51part 1
2/46
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 VariableTomcat 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 step
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
-
7/29/2019 Lab Record 51part 1
3/46
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:
ohttp://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, ta
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.jarin 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
the development directory I just discussed. Forgetting this setting is perhaps the most common mistake made
by beginning servlet programmers!
http://d0x.de/?http://localhost:8080/http://d0x.de/?http://localhost:8080/http://d0x.de/?http://localhost:8080/ -
7/29/2019 Lab Record 51part 1
4/46
Finally, you should include "." (the current directory) in the CLASSPATH. Otherwise, you will only be able t
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 us
the URL http://host/servlet/ServletName (orhttp://host/webAppName/servlet/ServletNameonce 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.
invoker
/servlet/*
http://d0x.de/?http://host/servlet/ServletNamehttp://d0x.de/?http://host/webAppName/servlet/ServletNamehttp://d0x.de/?http://host/webAppName/servlet/ServletNamehttp://d0x.de/?http://host/webAppName/servlet/ServletNamehttp://d0x.de/?http://host/servlet/ServletNamehttp://d0x.de/?http://host/webAppName/servlet/ServletName -
7/29/2019 Lab Record 51part 1
5/46
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 a
Jcreator or EditPlus.
http://d0x.de/?http://127.0.0.1:8080/examples/servlets/helloworld.htmlhttp://d0x.de/?http://localhost:8080/webdir/servlet/HelloWorldhttp://d0x.de/?http://127.0.0.1:8080/examples/servlets/helloworld.htmlhttp://d0x.de/?http://localhost:8080/webdir/servlet/HelloWorld -
7/29/2019 Lab Record 51part 1
6/46
2.E2.html
Welcome Page
J2ee Programing
Enter Your Name: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(" Java Programing");out.println("
"+msg+"
");out.println("
A Table with 5 rows and 5 columns");out.println("");out.println("1,11,21,31,41,5");out.println("2,12,22,32,42,5");out.println("3,13,23,33,43,5");out.println("4,14,24,34,44,5");out.println("5,15,25,35,45,5");out.println("");out.close();
}}
-
7/29/2019 Lab Record 51part 1
7/46
3.e3.html
Welcome PageJ2ee Programing
Enter Your Name:Enter Your Address: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(" Java Programing");out.println("Your Name :"+name+"");out.println("Your Address :"+address+"");out.close();}}
-
7/29/2019 Lab Record 51part 1
8/46
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 necessaryHttpSession 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);
elsecount=new Integer(count.intValue()+1);
session.putValue("tracker.count",count);out.println("Session Counts");out.println("Current Date And Time:"+new Date();+"");out.println("
The servlet has been"+count+((count.intVAlue()==1)?"time":"Times")+"accessedsince loaded");out.println("out.close();
}}
-
7/29/2019 Lab Record 51part 1
9/46
5.e5.htmlWelcome PageInter Servlet Communication
Enter Your Name:E5.javaimport 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("
"+msg+" From First Servlet
");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("
"+msg+" From Second Servlet
");out.close();}}6. e6.html -
7/29/2019 Lab Record 51part 1
10/46
Welcome PageJ2ee Programing
Enter Your Name:Enter Your Address:E6.javaimport 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(" J2ee Programing");out.println("Server Information
");out.println("Server Name :"+sname+"");out.println("Server Port :"+sport+"");out.close();}}
-
7/29/2019 Lab Record 51part 1
11/46
7. e7.html
Welcome PageJ2ee Programing
Enter Your Roll Number: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(" J2EE Programing");out.println("
Student Information");out.println("
Student Number"+sno);out.println("
Student Name :"+rs.getString(2);out.println("
Student Address :"+rs.getString(3);out.println("
Student Email Id :"+rs.getString(4);out.println("
Program of study :"+rs.getString(5);out.println("
Year of Admission :"+rs.getDate(6);}elseout.println("
Invalid Student Number Or Student doesn't Exist");}catch(Exception e){
-
7/29/2019 Lab Record 51part 1
12/46
out.println(e);}finally(){st.close();con.close();}out.close();}}
-
7/29/2019 Lab Record 51part 1
13/46
8. e8.html
Q3Login here
Enter User Name:Enter password: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, IOExceptio{
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("");out.println("Invalid User Name Password");out.println("");}out.close();}}
-
7/29/2019 Lab Record 51part 1
14/46
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("registration page");out.println("You are required to register first to get our services.
");out.println("");out.println("Name: ");out.println("Password: ");out.println("");out.println("");out.println("register");out.println("");}
public void doPost(HttpServletRequest request,HttpServletResponse response)throwsIOException,ServletException
{
response.setContentType("text/html");PrintWriter out=response.getWriter();String id=request.getParameter("uname");String pp=request.getParameter("upass");
out.println("ses4q9");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);
-
7/29/2019 Lab Record 51part 1
15/46
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("Welcome"+id+"");out.println("WELCOME TO
THE COMPUTER WORLD");out.println("");
out.println("ISBNTITLEAUTHORPRICE");
out.println("YEARPUBLISHER ");
rs=stat.executeQuery(sql);while(rs.next()){out.println("");int ISBN=rs.getInt(1);out.println(""+ISBN+"");String TITLE=rs.getString(2);out.println(""+TITLE+"");
String AUTHOR=rs.getString(3);out.println(""+AUTHOR+"");int PRICE=rs.getInt(4);out.println(""+PRICE+"");int catid=rs.getInt(5);int YEAR=rs.getInt(6);out.println(""+YEAR+"");String PUBLISHER=rs.getString(7);out.println(""+PUBLISHER+"");out.println("Order Now");out.println("");}
}}
else{
out.println("you need to be registered first");out.println("registration page");
}
-
7/29/2019 Lab Record 51part 1
16/46
}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("");
}
}
ses4q9a.jspimport 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("registration page");out.println("You are required to register first to get our services.
");out.println("");out.println("Name: ");
out.println("Password: ");
out.println("");out.println("");out.println("");
}
-
7/29/2019 Lab Record 51part 1
17/46
public void doPost(HttpServletRequest request,HttpServletResponse response)throwsIOException,ServletException
{response.setContentType("text/html");PrintWriter out=response.getWriter();String id=request.getParameter("uname");String pp=request.getParameter("upass");
out.println("ses4q9");out.println("WELCOME TO THE COMPUTER
WORLD");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 t
login page");}
}else{
s=con.createStatement();s.executeUpdate(ins_val);out.println("successfully registered");out.println("login");
}
}catch(Exception e)
{System.out.println(e);
}finally
{try{
if(rs!=null)rs.close();
if(stat!=null)
-
7/29/2019 Lab Record 51part 1
18/46
stat.close();if(s!=null)
s.close();if(con!=null)
con.close();}catch(Exception e){
System.out.println("hi1"+e);}
}out.println("");
}}ses4q9b.jspimport java.io.*;import java.sql.*;import javax.servlet.*;import javax.servlet.http.*;
public class ses4q9b extends HttpServlet{
public void doGet(HttpServletRequest request,HttpServletResponse response)throwsIOException,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("order page");out.println("you opted to place order for :"+TITLE+" of "+PUBLISHER +" publications for r
"+PRICE);out.println("");
out.println("Name :");out.println("Address :");out.println("Quantity :");out.println("");out.println("");}else{
response.sendRedirect("ses4q9");}
}
-
7/29/2019 Lab Record 51part 1
19/46
public void doPost(HttpServletRequest request,HttpServletResponse response)throwsIOException,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("ses4q9");out.println("WELCOME TO THE COMPUTER
WORLD");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("logout");}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("");
-
7/29/2019 Lab Record 51part 1
20/46
}else{
response.sendRedirect("ses4q9");}}
}sec4q9c.jspimport 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");}
}
}
-
7/29/2019 Lab Record 51part 1
21/46
10. E10.jsp
JSP programming
11. e11.jsp
JSP programming
-
7/29/2019 Lab Record 51part 1
22/46
12.e12.jsp
ses5q12WELCOME TO THE SYSTEM.
JAVA VERSION :JAVA HOME : OS NAME : USER NAME : USER HOME :USER DIRECTRY :13. e13.jsp
JSP programming
-
7/29/2019 Lab Record 51part 1
23/46
14. e14.jsp
JSP programming
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(" Java Programing");out.println("Your Name :"+name+"");out.println("Your Address :"+address+"");out.println("Your Date of Birth :"+dob+"");out.close();}}
-
7/29/2019 Lab Record 51part 1
24/46
15. e15.html
java programmingCustomer Form
Enter Customer Name:Enter Customer Address:Enter Customer Mobile No:E15.jsp
-
7/29/2019 Lab Record 51part 1
25/46
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);}}
%>
16. e16.jsp
JSP programmingIncluding the Program written in Exercise9
-
7/29/2019 Lab Record 51part 1
26/46
17. e17.jsp
Student who Born after 1985 are Sudent NameaddressM/tr>
,,
-
7/29/2019 Lab Record 51part 1
27/46
con.close();}catch(Exception e){System.out.println(e);}}%>
18. e18.jsp
JSP programming Displaying Personnel web page from JSP
19. e19.jspJSP ProgrammingProduct Information of Electronics GoodsInsert Form
Item NoItem Name -
7/29/2019 Lab Record 51part 1
28/46
Item PriceItem WaranteeItem ColorItem CompanyDisplay Form
Select an Item To Display Details -
7/29/2019 Lab Record 51part 1
29/46
E19.javaimport 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("J2EE Programing");out.println("
Product Information has been inserted");}elseout.println("
Product Information not inserted");}catch(Exception e)
{out.println(e);}finally(){try{ps.close();con.close();}catch(Exception e)
-
7/29/2019 Lab Record 51part 1
30/46
{out.println(e);}}out.close();}}
E19_1.jsp
Product Information Item NoItem name
Item PriceItem WaranteeItem ColorItem Company
-
7/29/2019 Lab Record 51part 1
31/46
}finally{try{if(ps!=null)
ps.close();if(con!=null)
con.close();}catch(Exception e){System.out.println(e);}}
%>
20. e20.xmlRamuDeenuFestival WhishesMay God give all the happiness to you and your family andi am wishing u the best wishes
Best WishesRamu
-
7/29/2019 Lab Record 51part 1
32/46
21. e21.xmlMy First Servlet
Introduction to servlet* What is Servlet* what are the advantage of servlet
Servlet Life Cycle
* Servlet Initialization* Servlet Reloading* Destroying a Servlet
22.e22.xmlwhite space problem
23. e23.xml
Visual Basic ProgrammingB.TechMohanNaveenJava ProgrammingM.Tech
Robert JohnSudhanshASP ProgrammingM.ScNeetaRavi
-
7/29/2019 Lab Record 51part 1
33/46
25. e25.htmlWelcome PageTable specification
Enter No Of RowsEnter No Of ColumnsE25.jspDisplaying TableDisplaying Table
-
7/29/2019 Lab Record 51part 1
34/46
a{text-decoration:none}
-
7/29/2019 Lab Record 51part 1
35/46
}
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";
}}-->recruitement agency
-
7/29/2019 Lab Record 51part 1
36/46
welcome To Recruitement AgencyAdd ClientsAdd CandidateSearch for jobsSearch by jobs fileds
Enter the Company DetailsName:
Address:
Status:
Field:
Designation:
Package_offer:
Experience_requi: -
7/29/2019 Lab Record 51part 1
37/46
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 intocom_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);}
}%>
-
7/29/2019 Lab Record 51part 1
38/46
Enter the Candidates DetailsName:
Email Address:
Eligibility:
Experience:
Post_required:
Pack_required: -
7/29/2019 Lab Record 51part 1
39/46
{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 intojoblist(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);}
}%>
Enter the client id:
-
7/29/2019 Lab Record 51part 1
40/46
}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: "+status+"(click on it to get the job as per requirement )");}else{
out.println("This Candidate is already settled");}
}//}
}catch(SQLException e)
{out.println("problem retrieving the data"+e);
}}%>
Select the required field:
-
7/29/2019 Lab Record 51part 1
41/46
getcompanieslist.jsprecruitement agency
Company Details
-
7/29/2019 Lab Record 51part 1
42/46
out.println(""+rs.getString(4)+"");out.println("");
}out.println("");out.println("back");
}catch(Exception e){
out.println("error inserting the candidate"+e);}
%>
getjob.javaimport 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("");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+"");
-
7/29/2019 Lab Record 51part 1
43/46
String getSpecification="select * from com_requirement where Designation LIKE'%"+items[0]+"%'";
rs=st.executeQuery(getSpecification);out.println("");out.println("");out.println("company_id Field Of Work DesignationPackag
OfferedExperience required");out.println("");
while(rs.next()){
out.println("");int list=rs.getInt(1);out.println(""+list+"");out.println(""+rs.getString(2)+"");out.println(""+rs.getString(3)+"");out.println(""+rs.getInt(4)+"");out.println(""+rs.getString(5)+"");out.println("");
}out.println("");
}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("");
-
7/29/2019 Lab Record 51part 1
44/46
}
}
readfields.javaimport 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("");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("");out.println("");nodeLst= doc.getElementsByTagName(field);out.println("");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("");out.println(getval);out.println("");
}}
-
7/29/2019 Lab Record 51part 1
45/46
out.println("");out.println("");out.println("");
}catch (Exception e) {
e.printStackTrace();}
out.println("");}
public void doPost(HttpServletRequest req,HttpServletResponse res)throws IOException,ServletException{
res.setContentType("text/html");PrintWriter out=res.getWriter();out.println("");
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("");out.println("");out.println("company_id Field Of Work DesignationPackag
OfferedExperience required");out.println("");
while(rs2.next()){
out.println("");int list=rs2.getInt(1);out.println(""+list+"");out.println(""+rs2.getString(2)+"");out.println(""+rs2.getString(3)+"");out.println(""+rs2.getInt(4)+"");out.println(""+rs2.getString(5)+"");out.println("");
}out.println("");out.println("back");
-
7/29/2019 Lab Record 51part 1
46/46
}catch(Exception e){
out.println("problem retrieving the data"+e);}
}}companies.xml
steel industries
home appliances
mobile repairing
accounting
electricity_development
godown management
sales
billing
inventory
site development
site management
softwares
online projects