Soumettre la recherche
Mettre en ligne
My java file
•
Télécharger en tant que DOCX, PDF
•
0 j'aime
•
1,355 vues
Anamika Chauhan
Suivre
Technologie
Signaler
Partager
Signaler
Partager
1 sur 41
Télécharger maintenant
Recommandé
Simple API for XML
Simple API for XML
guest2556de
201913046 wahyu septiansyah network programing
201913046 wahyu septiansyah network programing
wahyuseptiansyah
Server1
Server1
FahriIrawan3
Compatibility Detector Tool of Chrome extensions
Compatibility Detector Tool of Chrome extensions
Kai Cui
2012 JDays Bad Tests Good Tests
2012 JDays Bad Tests Good Tests
Tomek Kaczanowski
Unit testing CourseSites Apache Filter
Unit testing CourseSites Apache Filter
Wayan Wira
Web based development
Web based development
Mumbai Academisc
ReactJS for Programmers
ReactJS for Programmers
David Rodenas
Recommandé
Simple API for XML
Simple API for XML
guest2556de
201913046 wahyu septiansyah network programing
201913046 wahyu septiansyah network programing
wahyuseptiansyah
Server1
Server1
FahriIrawan3
Compatibility Detector Tool of Chrome extensions
Compatibility Detector Tool of Chrome extensions
Kai Cui
2012 JDays Bad Tests Good Tests
2012 JDays Bad Tests Good Tests
Tomek Kaczanowski
Unit testing CourseSites Apache Filter
Unit testing CourseSites Apache Filter
Wayan Wira
Web based development
Web based development
Mumbai Academisc
ReactJS for Programmers
ReactJS for Programmers
David Rodenas
Testing Java Code Effectively - BaselOne17
Testing Java Code Effectively - BaselOne17
Andres Almiray
ES3-2020-06 Test Driven Development (TDD)
ES3-2020-06 Test Driven Development (TDD)
David Rodenas
ES3-2020-07 Testing techniques
ES3-2020-07 Testing techniques
David Rodenas
33rd Degree 2013, Bad Tests, Good Tests
33rd Degree 2013, Bad Tests, Good Tests
Tomek Kaczanowski
Software Testing - Invited Lecture at UNSW Sydney
Software Testing - Invited Lecture at UNSW Sydney
julien.ponge
Java 7 Launch Event at LyonJUG, Lyon France. Fork / Join framework and Projec...
Java 7 Launch Event at LyonJUG, Lyon France. Fork / Join framework and Projec...
julien.ponge
Java 7 LavaJUG
Java 7 LavaJUG
julien.ponge
JavaExamples
JavaExamples
Suman Astani
Agile Android
Agile Android
Godfrey Nolan
Testing My Patience
Testing My Patience
Adam Lowry
TDD CrashCourse Part4: Improving Testing
TDD CrashCourse Part4: Improving Testing
David Rodenas
TDD CrashCourse Part5: Testing Techniques
TDD CrashCourse Part5: Testing Techniques
David Rodenas
Angular mix chrisnoring
Angular mix chrisnoring
Christoffer Noring
Migrating from Flux to Redux. Why and how.
Migrating from Flux to Redux. Why and how.
Astrails
GMock framework
GMock framework
corehard_by
Laporan tugas network programming
Laporan tugas network programming
RahmatHamdani2
Java 8: the good, the bad and the ugly (JBCNConf 2017)
Java 8: the good, the bad and the ugly (JBCNConf 2017)
Brian Vermeer
Android TDD
Android TDD
Godfrey Nolan
Workshop 1: Good practices in JavaScript
Workshop 1: Good practices in JavaScript
Visual Engineering
Inside PyMongo - MongoNYC
Inside PyMongo - MongoNYC
Mike Dirolf
Jsp And Jdbc
Jsp And Jdbc
Roy Antony Arnold G
30 5 Database Jdbc
30 5 Database Jdbc
phanleson
Contenu connexe
Tendances
Testing Java Code Effectively - BaselOne17
Testing Java Code Effectively - BaselOne17
Andres Almiray
ES3-2020-06 Test Driven Development (TDD)
ES3-2020-06 Test Driven Development (TDD)
David Rodenas
ES3-2020-07 Testing techniques
ES3-2020-07 Testing techniques
David Rodenas
33rd Degree 2013, Bad Tests, Good Tests
33rd Degree 2013, Bad Tests, Good Tests
Tomek Kaczanowski
Software Testing - Invited Lecture at UNSW Sydney
Software Testing - Invited Lecture at UNSW Sydney
julien.ponge
Java 7 Launch Event at LyonJUG, Lyon France. Fork / Join framework and Projec...
Java 7 Launch Event at LyonJUG, Lyon France. Fork / Join framework and Projec...
julien.ponge
Java 7 LavaJUG
Java 7 LavaJUG
julien.ponge
JavaExamples
JavaExamples
Suman Astani
Agile Android
Agile Android
Godfrey Nolan
Testing My Patience
Testing My Patience
Adam Lowry
TDD CrashCourse Part4: Improving Testing
TDD CrashCourse Part4: Improving Testing
David Rodenas
TDD CrashCourse Part5: Testing Techniques
TDD CrashCourse Part5: Testing Techniques
David Rodenas
Angular mix chrisnoring
Angular mix chrisnoring
Christoffer Noring
Migrating from Flux to Redux. Why and how.
Migrating from Flux to Redux. Why and how.
Astrails
GMock framework
GMock framework
corehard_by
Laporan tugas network programming
Laporan tugas network programming
RahmatHamdani2
Java 8: the good, the bad and the ugly (JBCNConf 2017)
Java 8: the good, the bad and the ugly (JBCNConf 2017)
Brian Vermeer
Android TDD
Android TDD
Godfrey Nolan
Workshop 1: Good practices in JavaScript
Workshop 1: Good practices in JavaScript
Visual Engineering
Inside PyMongo - MongoNYC
Inside PyMongo - MongoNYC
Mike Dirolf
Tendances
(20)
Testing Java Code Effectively - BaselOne17
Testing Java Code Effectively - BaselOne17
ES3-2020-06 Test Driven Development (TDD)
ES3-2020-06 Test Driven Development (TDD)
ES3-2020-07 Testing techniques
ES3-2020-07 Testing techniques
33rd Degree 2013, Bad Tests, Good Tests
33rd Degree 2013, Bad Tests, Good Tests
Software Testing - Invited Lecture at UNSW Sydney
Software Testing - Invited Lecture at UNSW Sydney
Java 7 Launch Event at LyonJUG, Lyon France. Fork / Join framework and Projec...
Java 7 Launch Event at LyonJUG, Lyon France. Fork / Join framework and Projec...
Java 7 LavaJUG
Java 7 LavaJUG
JavaExamples
JavaExamples
Agile Android
Agile Android
Testing My Patience
Testing My Patience
TDD CrashCourse Part4: Improving Testing
TDD CrashCourse Part4: Improving Testing
TDD CrashCourse Part5: Testing Techniques
TDD CrashCourse Part5: Testing Techniques
Angular mix chrisnoring
Angular mix chrisnoring
Migrating from Flux to Redux. Why and how.
Migrating from Flux to Redux. Why and how.
GMock framework
GMock framework
Laporan tugas network programming
Laporan tugas network programming
Java 8: the good, the bad and the ugly (JBCNConf 2017)
Java 8: the good, the bad and the ugly (JBCNConf 2017)
Android TDD
Android TDD
Workshop 1: Good practices in JavaScript
Workshop 1: Good practices in JavaScript
Inside PyMongo - MongoNYC
Inside PyMongo - MongoNYC
Similaire à My java file
Jsp And Jdbc
Jsp And Jdbc
Roy Antony Arnold G
30 5 Database Jdbc
30 5 Database Jdbc
phanleson
JDBC Tutorial
JDBC Tutorial
Information Technology
Spring Capitulo 05
Spring Capitulo 05
Diego Pacheco
jdbc
jdbc
vikram singh
ActiveWeb: Chicago Java User Group Presentation
ActiveWeb: Chicago Java User Group Presentation
ipolevoy
[DSBW Spring 2009] Unit 07: WebApp Design Patterns & Frameworks (3/3)
[DSBW Spring 2009] Unit 07: WebApp Design Patterns & Frameworks (3/3)
Carles Farré
Advance Java Programs skeleton
Advance Java Programs skeleton
Iram Ramrajkar
What's Coming in Spring 3.0
What's Coming in Spring 3.0
Matt Raible
my accadanic project ppt
my accadanic project ppt
Manivel Thiruvengadam
Jersey framework
Jersey framework
knight1128
Jdbc
Jdbc
smvdurajesh
Executing Sql Commands
Executing Sql Commands
phanleson
Executing Sql Commands
Executing Sql Commands
leminhvuong
JDBC for CSQL Database
JDBC for CSQL Database
jitendral
General Principles of Web Security
General Principles of Web Security
jemond
Web CrawlersrcedusmulylecrawlerController.javaWeb Crawler.docx
Web CrawlersrcedusmulylecrawlerController.javaWeb Crawler.docx
celenarouzie
Refactoring Jdbc Programming
Refactoring Jdbc Programming
chanwook Park
Taking Apache Camel For A Ride
Taking Apache Camel For A Ride
Bruce Snyder
Data Access with JDBC
Data Access with JDBC
BG Java EE Course
Similaire à My java file
(20)
Jsp And Jdbc
Jsp And Jdbc
30 5 Database Jdbc
30 5 Database Jdbc
JDBC Tutorial
JDBC Tutorial
Spring Capitulo 05
Spring Capitulo 05
jdbc
jdbc
ActiveWeb: Chicago Java User Group Presentation
ActiveWeb: Chicago Java User Group Presentation
[DSBW Spring 2009] Unit 07: WebApp Design Patterns & Frameworks (3/3)
[DSBW Spring 2009] Unit 07: WebApp Design Patterns & Frameworks (3/3)
Advance Java Programs skeleton
Advance Java Programs skeleton
What's Coming in Spring 3.0
What's Coming in Spring 3.0
my accadanic project ppt
my accadanic project ppt
Jersey framework
Jersey framework
Jdbc
Jdbc
Executing Sql Commands
Executing Sql Commands
Executing Sql Commands
Executing Sql Commands
JDBC for CSQL Database
JDBC for CSQL Database
General Principles of Web Security
General Principles of Web Security
Web CrawlersrcedusmulylecrawlerController.javaWeb Crawler.docx
Web CrawlersrcedusmulylecrawlerController.javaWeb Crawler.docx
Refactoring Jdbc Programming
Refactoring Jdbc Programming
Taking Apache Camel For A Ride
Taking Apache Camel For A Ride
Data Access with JDBC
Data Access with JDBC
Dernier
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
Maria Levchenko
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?
Antenna Manufacturer Coco
Advantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your Business
Pixlogix Infotech
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
Earley Information Science
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
The Digital Insurer
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
apidays
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
Anna Loughnan Colquhoun
How to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
naman860154
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
giselly40
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
Rafal Los
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Drew Madelung
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
wesley chun
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024
Results
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
Radu Cotescu
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
Delhi Call girls
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
Safe Software
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
Martijn de Jong
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
Joaquim Jorge
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
Michael W. Hawkins
Dernier
(20)
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?
Advantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your Business
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
How to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
My java file
1.
Experiment-1<br />Aim:- Program
to access a table “table1” from MS-Access using java code.<br />Program:-<br />import java.sql.*;<br /> public class Main {<br />public static void main(String[] args)<br /> {<br /> try {<br /> Class.forName(quot; sun.jdbc.odbc.JdbcOdbcDriverquot; );<br /> }<br /> catch(Exception e)<br /> {<br /> System.out.println(e);<br /> }<br /> try<br /> {<br /> Connection conn;<br /> Statement stmt;<br /> ResultSet rs;<br /> conn=DriverManager.getConnection(quot; Jdbc:Odbc:anamikaquot; ,quot; anamikaquot; ,quot; anamikaquot; );<br /> stmt=conn.createStatement();<br /> rs=stmt.executeQuery(quot; Select * from table1quot; );<br /> while(rs.next())<br /> {<br /> System.out.println(rs.getString(quot; namequot; ));<br /> System.out.println(rs.getString(quot; rollnoquot; ));<br /> }<br /> }<br /> catch(Exception e)<br /> {<br /> System.out.println(e);<br /> }<br />}<br />}<br />Output<br />Experiment:-2<br />Aim:- Program to access a table “table1” from derby database using java code.<br />Program:-<br />import java.sql.*;<br /> public class Main {<br />public static void main(String[] args)<br /> {<br /> try {<br /> Class.forName(quot; org.apache.derby.jdbc.ClientDriver quot; );<br /> }<br /> catch(Exception e)<br /> {<br /> System.out.println(e);<br /> }<br /> try<br /> {<br /> Connection conn;<br /> Statement stmt;<br /> ResultSet rs;<br /> conn=DriverManager.getConnection(quot; jdbc:derby://localhost:1527/anamikaquot; ,quot; anamikaquot; ,quot; anamikaquot; );<br /> stmt=conn.createStatement();<br /> rs=stmt.executeQuery(quot; Select * from table1quot; );<br /> while(rs.next())<br /> {<br /> System.out.println(rs.getString(quot; namequot; ));<br /> System.out.println(rs.getString(quot; rollnoquot; ));<br /> }<br /> }<br /> catch(Exception e)<br /> {<br /> System.out.println(e);<br /> }<br />}<br />}<br />Output:-<br />Experiment-3<br />Aim:-Program for invoking a remote method using interface.<br />Program:-<br />Product.java<br />import java.rmi.*;<br />public interface product extends Remote<br />{<br />public String getname() throws RemoteException;<br />}<br />Product_impl.java<br />import java.rmi.*;<br />import java.rmi.server.*;<br />public class product_impl extends UnicastRemoteObject implements product<br />{<br />public String name;<br />public product_impl(String name) throws RemoteException<br />{this.name=name;<br />}<br />public String getname()<br />{<br />return name;<br />}<br /> }<br />Productserver.java<br />import java.rmi.*;<br />import java.rmi.registry.*;<br />public class productserver<br />{<br />public static void main(String s[])<br />{<br />try<br />{<br />LocateRegistry.getRegistry(1099);<br />product_impl p1=new product_impl(quot; javaquot; );<br />Naming.rebind(quot; xyzquot; ,p1);<br />}<br />catch(Exception e)<br />{<br />System.out.println(e);<br />}<br />}<br />}<br />Productclient.java<br />import java.rmi.*;<br />import java.rmi.registry.*;<br /> class productclient<br />{<br />public static void main(String s[])<br />{<br />try<br />{<br />product p=(product)Naming.lookup(quot; rmi://localhost:1099/xyzquot; );<br />System.out.println(p.getname());<br />}<br />catch(Exception e)<br />{<br />System.out.println(e);<br />}<br />}<br />}<br />Generating stub and skeleton<br />Start server<br />Start client<br />Experiment:-4<br />Aim:- Program that implement a simple servlet program<br />Program:-<br />//Prog for simple servelet<br />import java.io.IOException;<br />import java.io.PrintWriter;<br />import javax.servlet.ServletException;<br />import javax.servlet.annotation.WebServlet;<br />import javax.servlet.http.HttpServlet;<br />import javax.servlet.http.HttpServletRequest;<br />import javax.servlet.http.HttpServletResponse;<br />/**<br /> *<br /> * @author anamika<br /> */<br />@WebServlet(name=quot; NewServletquot; , urlPatterns={quot; /NewServletquot; })<br />public class NewServlet extends HttpServlet {<br /> protected void processRequest(HttpServletRequest request, HttpServletResponse response)<br /> throws ServletException, IOException {<br /> response.setContentType(quot; text/html;charset=UTF-8quot; );<br /> PrintWriter out = response.getWriter();<br /> try {<br /> // TODO output your page here<br /> out.println(quot; <html>quot; );<br /> out.println(quot; <head>quot; );<br /> out.println(quot; <title>Servlet NewServlet</title>quot; ); <br /> out.println(quot; </head>quot; );<br /> out.println(quot; <body>quot; );<br /> out.println(quot; <h1>Servlet NewServlet at quot; + request.getContextPath () + quot; </h1>quot; );<br /> out.println(quot; </body>quot; );<br /> out.println(quot; This is my first servlet programquot; );<br /> out.println(quot; </html>quot; );<br /> <br /> } finally { <br /> out.close();<br /> }<br /> } <br />Output<br /> <br />Experiment 5<br />Program:-servlet connectivity wid derby<br />import java.io.*;<br />import java.sql.*;<br />import javax.servlet.ServletConfig;<br />import javax.servlet.ServletException;<br />import javax.servlet.http.*;<br />/**<br /> *<br /> * @author student<br /> * @version<br /> */<br />public class NewServlet extends HttpServlet {<br /> Connection dbconnection;<br /> ResultSet resultset;<br /> /** Initializes the servlet.<br /> */<br /> public void init() throws ServletException {<br /> ServletConfig config = getServletConfig();<br /> String driverClassName = config.getInitParameter(quot; driverclassnamequot; );<br /> String dbURL = config.getInitParameter(quot; dburlquot; );<br /> String username = config.getInitParameter(quot; usernamequot; );<br /> String dbpassword = config.getInitParameter(quot; dbpasswordquot; );<br /> try<br /> {<br /> Class.forName(driverClassName);<br /> }<br /> catch(ClassNotFoundException cnfe)<br /> {<br /> System.err.println(quot; Error loading driver: quot; + cnfe);<br /> }<br /> try<br /> {<br /> dbconnection = DriverManager.getConnection(dbURL, username, dbpassword);<br /> }<br /> catch(SQLException sqle)<br /> {<br /> System.err.println(quot; Connection error: quot; + sqle);<br /> }<br /> }<br /> /** Destroys the servlet.<br /> */<br /> public void destroy() {<br /> }<br /> /** Processes requests for both HTTP <code>GET</code> and <code>POST</code> methods.<br /> * @param request servlet request<br /> * @param response servlet response<br /> */<br /> protected void processRequest(HttpServletRequest request, HttpServletResponse response)<br /> throws ServletException, IOException {<br /> response.setContentType(quot; text/htmlquot; );<br /> PrintWriter out = response.getWriter();<br /> //TODO output your page here<br /> out.println(quot; <html>quot; );<br /> out.println(quot; <head>quot; );<br /> out.println(quot; <title>Servlet</title>quot; );<br /> out.println(quot; </head>quot; );<br /> out.println(quot; <body>quot; );<br /> try<br /> {<br /> Statement statement = dbconnection.createStatement();<br /> String sqlString = quot; SELECT * FROM app.untitledquot; ;<br /> resultset=statement.executeQuery(sqlString);<br /> while(resultset.next())<br /> {<br /> out.println(resultset.getString(quot; namequot; ));<br /> out.println(resultset.getString(quot; rollnoquot; ));<br /> // password = resultset.getString(quot; UserPasswordquot; );<br /> }<br /> }<br /> catch(SQLException sqle)<br /> {<br /> System.err.println(quot; Connection error: quot; + sqle);<br /> }<br /> // out.println(quot; subahshquot; );<br /> out.println(quot; </body>quot; );<br /> out.println(quot; </html>quot; );<br /> out.close();<br /> }<br /> /** Handles the HTTP <code>GET</code> method.<br /> * @param request servlet request<br /> * @param response servlet response<br /> */<br /> protected void doGet(HttpServletRequest request, HttpServletResponse response)<br /> throws ServletException, IOException {<br /> processRequest(request, response);<br /> }<br /> /** Handles the HTTP <code>POST</code> method.<br /> * @param request servlet request<br /> * @param response servlet response<br /> */<br /> protected void doPost(HttpServletRequest request, HttpServletResponse response)<br /> throws ServletException, IOException {<br /> processRequest(request, response);<br /> }<br /> /** Returns a short description of the servlet.<br /> */<br /> public String getServletInfo() {<br /> return quot; Short descriptionquot; ;<br /> }<br />}<br />Web.xml<br /><?xml version=quot; 1.0quot; encoding=quot; UTF-8quot; ?><br /><web-app version=quot; 3.0quot; xmlns=quot; http://java.sun.com/xml/ns/javaeequot; xmlns:xsi=quot; http://www.w3.org/2001/XMLSchema-instancequot; xsi:schemaLocation=quot; http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsdquot; ><br /> <servlet><br /> <servlet-name>NewServlet</servlet-name><br /> <servlet-class>NewServlet</servlet-class><br /> <init-param><br /> <param-name>driverclassname</param-name><br /> <param-value>org.apache.derby.jdbc.ClientDriver</param-value><br /> </init-param><br /> <init-param><br /> <param-name>dburl</param-name><br /> <param-value>jdbc:derby://localhost:1527/anamika</param-value><br /> </init-param><br /> <init-param><br /> <param-name>username</param-name><br /> <param-value>anamika</param-value><br /> </init-param><br /> <init-param><br /> <param-name>dbpassword</param-name><br /> <param-value>anamika</param-value><br /> </init-param><br /> </servlet><br /> <servlet-mapping><br /> <servlet-name>NewServlet</servlet-name><br /> <url-pattern>/NewServlet</url-pattern><br /> </servlet-mapping><br /> <session-config><br /> <session-timeout><br /> 30<br /> </session-timeout><br /> </session-config><br /> <welcome-file-list><br /> <welcome-file>index.jsp</welcome-file><br /> </welcome-file-list><br /> </web-app><br />Output<br />Experiment:-login using servelts<br />import java.io.*;<br />import java.sql.*;<br />import javax.servlet.ServletConfig;<br />import javax.servlet.ServletException;<br />import javax.servlet.http.*;<br />/**<br /> *<br /> * @author student<br /> * @version<br /> */<br />public class NewServlet extends HttpServlet {<br /> Connection dbconnection;<br /> ResultSet resultset;<br /> /** Initializes the servlet.<br /> */<br /> String userid;<br /> String password;<br /> public void init() throws ServletException {<br /> ServletConfig config = getServletConfig();<br /> String driverClassName = config.getInitParameter(quot; driverclassnamequot; );<br /> String dbURL = config.getInitParameter(quot; dburlquot; );<br /> String username = config.getInitParameter(quot; usernamequot; );<br /> String dbpassword = config.getInitParameter(quot; dbpasswordquot; );<br /> try<br /> {<br /> Class.forName(driverClassName);<br /> }<br /> catch(ClassNotFoundException cnfe)<br /> {<br /> System.err.println(quot; Error loading driver: quot; + cnfe);<br /> }<br /> try<br /> {<br /> dbconnection = DriverManager.getConnection(dbURL, username, dbpassword);<br /> }<br /> catch(SQLException sqle)<br /> {<br /> System.err.println(quot; Connection error: quot; + sqle);<br /> }<br /> }<br /> /** Destroys the servlet.<br /> */<br /> public void destroy() {<br /> }<br /> /** Processes requests for both HTTP <code>GET</code> and <code>POST</code> methods.<br /> * @param request servlet request<br /> * @param response servlet response<br /> */<br /> protected void processRequest(HttpServletRequest request, HttpServletResponse response)<br /> throws ServletException, IOException {<br /> response.setContentType(quot; text/htmlquot; );<br /> PrintWriter out = response.getWriter();<br /> // String s1=request.getParameter(quot; t1quot; );<br /> // String ps=request.getParameter(quot; p1quot; );<br /> try<br /> {<br /> Statement statement = dbconnection.createStatement();<br /> String sqlString = quot; SELECT * FROM app.student1 WHERE username='quot; +request.getParameter(quot; useridquot; )+quot; 'AND password='quot; +request.getParameter(quot; passquot; )+quot; 'quot; ;<br /> resultset=statement.executeQuery(sqlString);<br /> while(resultset.next())<br /> {<br /> userid = resultset.getString(quot; usernamequot; );<br /> password = resultset.getString(quot; passwordquot; );<br /> }<br /> }<br /> catch(SQLException sqle)<br /> {<br /> System.err.println(quot; Connection error: quot; + sqle);<br /> }<br /> if(password.equals(request.getParameter(quot; passquot; )) && userid.equals(request.getParameter(quot; useridquot; )))<br /> {<br /> response.sendRedirect(quot; /WebApplication2/correct.htmlquot; );<br /> }<br /> else<br /> {<br /> response.sendRedirect(quot; /WebApplication2/incorrect.htmlquot; );<br /> }<br /> //TODO output your page here<br /> out.println(quot; <html>quot; );<br /> out.println(quot; <head>quot; );<br /> out.println(quot; <title>Servlet</title>quot; );<br /> out.println(quot; </head>quot; );<br /> out.println(quot; <body>quot; );<br /> // out.println(s1);<br /> // out.println(ps);<br /> out.println(quot; </body>quot; );<br /> out.println(quot; </html>quot; );<br /> out.close();<br /> }<br /> /** Handles the HTTP <code>GET</code> method.<br /> * @param request servlet request<br /> * @param response servlet response<br /> */<br /> protected void doGet(HttpServletRequest request, HttpServletResponse response)<br /> throws ServletException, IOException {<br /> processRequest(request, response);<br /> }<br /> /** Handles the HTTP <code>POST</code> method.<br /> * @param request servlet request<br /> * @param response servlet response<br /> */<br /> protected void doPost(HttpServletRequest request, HttpServletResponse response)<br /> throws ServletException, IOException {<br /> processRequest(request, response);<br /> }<br /> /** Returns a short description of the servlet.<br /> */<br /> public String getServletInfo() {<br /> return quot; Short descriptionquot; ;<br /> }<br />}<br />Mytable is student1 wid username,password<br />loginframe<br />Top of Form<br />Top of Form<br /><form action=quot; /Program6/NewServletquot; method=quot; POSTquot; ><br /> <h1>UserId<input type=quot; textquot; name=quot; useridquot; value=quot; quot; size=quot; 20quot; /> <br /> Password<input type=quot; passwordquot; name=quot; passquot; value=quot; quot; size=quot; 20quot; /><br /> <input type=quot; submitquot; value=quot; loginquot; /></h1><br />Correct.html<br />Incorrect.html<br />Web.xml:-same as above<br />Experiment:-login using jsp<br />create jsp and insert code of loginframe into its body.rest all is same as above and delete correct.html<br />Experiment:-session management<br />Changes are only underlined <br />/*<br /> * To change this template, choose Tools | Templates<br /> * and open the template in the editor.<br /> */<br />import java.io.*;<br />import java.sql.*;<br />import javax.servlet.ServletConfig;<br />import javax.servlet.ServletException;<br />import javax.servlet.http.*;<br />/**<br /> *<br /> * @author student<br /> * @version<br /> */<br />public class NewServlet extends HttpServlet {<br /> Connection dbconnection;<br /> ResultSet resultset;<br /> /** Initializes the servlet.<br /> */<br /> String userid;<br /> String password;<br /> public void init() throws ServletException {<br /> ServletConfig config = getServletConfig();<br /> String driverClassName = config.getInitParameter(quot; driverclassnamequot; );<br /> String dbURL = config.getInitParameter(quot; dburlquot; );<br /> String username = config.getInitParameter(quot; usernamequot; );<br /> String dbpassword = config.getInitParameter(quot; dbpasswordquot; );<br /> try<br /> {<br /> Class.forName(driverClassName);<br /> }<br /> catch(ClassNotFoundException cnfe)<br /> {<br /> System.err.println(quot; Error loading driver: quot; + cnfe);<br /> }<br /> try<br /> {<br /> dbconnection = DriverManager.getConnection(dbURL, username, dbpassword);<br /> }<br /> catch(SQLException sqle)<br /> {<br /> System.err.println(quot; Connection error: quot; + sqle);<br /> }<br /> }<br /> /** Destroys the servlet.<br /> */<br /> public void destroy() {<br /> }<br /> /** Processes requests for both HTTP <code>GET</code> and <code>POST</code> methods.<br /> * @param request servlet request<br /> * @param response servlet response<br /> */<br /> protected void processRequest(HttpServletRequest request, HttpServletResponse response)<br /> throws ServletException, IOException {<br /> response.setContentType(quot; text/htmlquot; );<br /> PrintWriter out = response.getWriter();<br /> // String s1=request.getParameter(quot; t1quot; );<br /> // String ps=request.getParameter(quot; p1quot; );<br /> HttpSession s=request.getSession();<br /> try<br /> {<br /> Statement statement = dbconnection.createStatement();<br /> String sqlString = quot; SELECT * FROM app.STUDENT WHERE userid='quot; +request.getParameter(quot; useridquot; )+quot; 'AND pass='quot; +request.getParameter(quot; passquot; )+quot; 'quot; ;<br /> resultset=statement.executeQuery(sqlString);<br /> while(resultset.next())<br /> {<br /> userid = resultset.getString(quot; useridquot; );<br /> password = resultset.getString(quot; passquot; );<br /> }<br /> }<br /> catch(SQLException sqle)<br /> {<br /> System.err.println(quot; Connection error: quot; + sqle);<br /> }<br /> if(password.equals(request.getParameter(quot; passquot; )) && userid.equals(request.getParameter(quot; useridquot; )))<br /> {<br /> response.sendRedirect(quot; /WebApplication3/correct.jsp?ssid=quot; +s.getId()+quot; quot; );<br /> }<br /> else<br /> {<br /> response.sendRedirect(quot; /WebApplication3/incorrect.jsp?ssid=quot; +s.getId()+quot; quot; );<br /> }<br /> //TODO output your page here<br /> out.println(quot; <html>quot; );<br /> out.println(quot; <head>quot; );<br /> out.println(quot; <title>Servlet</title>quot; );<br /> out.println(quot; </head>quot; );<br /> out.println(quot; <body>quot; );<br /> // out.println(s1);<br /> // out.println(ps);<br /> out.println(quot; </body>quot; );<br /> out.println(quot; </html>quot; );<br /> out.close();<br /> }<br /> /** Handles the HTTP <code>GET</code> method.<br /> * @param request servlet request<br /> * @param response servlet response<br /> */<br /> protected void doGet(HttpServletRequest request, HttpServletResponse response)<br /> throws ServletException, IOException {<br /> processRequest(request, response);<br /> }<br /> /** Handles the HTTP <code>POST</code> method.<br /> * @param request servlet request<br /> * @param response servlet response<br /> */<br /> protected void doPost(HttpServletRequest request, HttpServletResponse response)<br /> throws ServletException, IOException {<br /> processRequest(request, response);<br /> }<br /> /** Returns a short description of the servlet.<br /> */<br /> public String getServletInfo() {<br /> return quot; Short descriptionquot; ;<br /> }<br />}<br /><%-- <br /> Document : correct<br /> Created on : Apr 10, 2011, 3:18:30 AM<br /> Author : babu<br />--%><br /><%@page contentType=quot; text/htmlquot; pageEncoding=quot; UTF-8quot; %><br /><!DOCTYPE HTML PUBLIC quot; -//W3C//DTD HTML 4.01 Transitional//ENquot; <br /> quot; http://www.w3.org/TR/html4/loose.dtdquot; ><br /><html><br /> <head><br /> <meta http-equiv=quot; Content-Typequot; content=quot; text/html; charset=UTF-8quot; ><br /> <title>JSP Page</title><br /> </head><br /> <body><br /> <%!<br />String userid;<br />String in_session;<br />%><br /><%<br />userid=request.getParameter(quot; ssidquot; );<br />String Id=session.getId();<br />//out.println(userid);<br />//out.println(Id);<br />//if(Id.equals(userid))<br /> if(request.getParameter(quot; ssidquot; ).equals(session.getId()))<br />{%><br /> correct yipee<br /> <% }<br />else{<br /> %><br /> // response.sendRedirect(quot; abc.htmlquot; );<br /> <jsp:forward page=quot; abc.htmlquot; /><br /> <%<br />}<br />session.invalidate();<br />%><br /> </body><br /></html><br />Same of incorrect.jsp only make correct inplace of correct<br />Web.xml same as previous<br />Output<br />This above url pasted on another tab and we get d output<br />Experiment:-jsp connectivity<br /><%-- <br /> Document : jspconnectivity<br /> Created on : Apr 10, 2011, 3:38:37 AM<br /> Author : babu<br />--%><br /><%@page language=quot; javaquot; import=quot; java.sql.*quot; %><br /><!DOCTYPE HTML PUBLIC quot; -//W3C//DTD HTML 4.01 Transitional//ENquot; <br /> quot; http://www.w3.org/TR/html4/loose.dtdquot; ><br /><html><br /> <head><br /> <meta http-equiv=quot; Content-Typequot; content=quot; text/html; charset=UTF-8quot; ><br /> <title>JSP Page</title><br /> </head><br /> <body><br /> <%<br /> try {<br /> Class.forName(quot; org.apache.derby.jdbc.ClientDriverquot; );<br /> }<br /> catch(Exception e)<br /> {<br /> System.out.println(e);<br /> }<br /> try<br /> {<br /> Connection conn;<br /> Statement stmt;<br /> ResultSet rs;<br /> conn=DriverManager.getConnection(quot; jdbc:derby://localhost:1527/anamikaquot; ,quot; anamikaquot; ,quot; anamikaquot; );<br /> stmt=conn.createStatement();<br /> rs=stmt.executeQuery(quot; Select * from app.studentquot; );<br /> // PrintStream out= new PrintStream(response.getOutputStream());<br /> //PrintStream out= new PrintStream(response.getOutputStream());<br /> //response.setContentType(quot; text/htmlquot; );<br /> //response.setContentType(quot; text/htmlquot; );<br /> out.println(quot; <html>quot; );<br /> out.println(quot; <head>quot; );<br /> out.println(quot; <title>My table</title>quot; );<br /> out.println(quot; <title>my personal details</title>quot; );<br /> out.println(quot; </head>quot; );<br /> out.println(quot; <body>quot; );<br /> out.println(quot; <center>quot; );<br />//out.println(“<center>”);<br /> out.print(quot; <table border=1>quot; );<br /> out.print(quot; <td>userid</td>quot; );<br /> out.print(quot; <td>password</td>quot; );<br /> // System.out.println(quot; Rollno Namequot; );<br /> while(rs.next())<br /> {<br /> //out.println(rs.getString(quot; useridquot; ));<br /> // out.println(rs.getString(quot; passquot; ));<br /> out.print(quot; <tr>quot; );<br /> out.print(quot; <td>quot; +rs.getString(1));<br /> String s=rs.getString(2);<br /> out.print(quot; <td>quot; +s);<br /> }<br /> //out.println(“</center>”);<br /> out.println(quot; </center>quot; );<br /> out.println(quot; </table>quot; );<br /> out.println(quot; </body>quot; );<br /> out.println(quot; </html>quot; );<br /> }<br /> catch(Exception e)<br /> {<br /> System.out.println(e);<br /> }<br />%><br /> </body><br /></html><br />Output<br />
Télécharger maintenant