Ip Slide Notes
Ip Slide Notes
? Forms provide a means of submitting information from the client to the server. A form consists of one or more: text input boxes clickable radio buttons multiple-choice check boxes pull-down menus clickable images text and images (maybe instructions on form use); <FORM action="mailto:[email protected]" method="post" enctype="text/plain"> Form Attributes: action - gives the URL of the application that is to receive and process the forms data; most of these are kept in cgi-bin or cgi-win; Common Gateway Interface binaries; enctype - the browser encodes the form's data before it is passed to the server method - sets the HTTP method that the browser uses to send the form's data to the server for processing; Either POST or GET Post The browser sends the data in two steps: contacts the form processing server specified in the action attribute; sends the data to the server in a separate transmission; GET contacts the form-processing server and sends the form data in a single transmission step: The browser appends the data to the form's action URL, separated by the? Character. If security is an issue, choose POST because GET places the form parameters directly in the application URL (easily captured by network sniffers); POST can take advantage of encryption when transmitting the parameters as a separate transaction; The <input> tag Text Field <input type="text" name="textfield" value="with an initial value">
Buttons: A submit button: <input type="submit" name="Submit" value="Submit"> A reset button: <input type="reset" name="Submit2" value="Reset"> A plain button: <input type="button" name="Submit3" value="Push Me">
submit: send data reset: restore all form elements to their initial state button: take some action as specified by JavaScript name: used to reference this form element from JavaScript Checkbox: <input type="checkbox" name="checkbox value="checkbox" checked>
Radio buttons : Radio buttons:<br> <input type="radio" name="radiobutton" value="myValue1"> male<br> <input type="radio" name="radiobutton" value="myValue2" checked>female
HTML FRAMES
Advantage of using frames: flexibility in design information in different Web pages Remove redundancy. Site easier to manage. Update only a few files rather than the whole. Disadvantages to Using Frames The browser has to load multiple HTML files, thus increasing wait time Some older browsers cannot display frames. Some users do not like using frames. Frames can use up valuable screen space. The source code is hidden. Asterisk (*) Tells the browser to allocate any unclaimed space in the frameset to the particular row or column. <frameset rows=160,*> <frameset rows=*,*,*> = 3 equal rows
Reserved target names are special names that can be used in place of a frame name as the target. All reserved target names begin with the underscore character ( _ ) to distinguish them from other target names. And they are case-sensitive, all small letters -blank: loads document into new browser window -self: loads the document in the same frame or the window that contain hyperlink tag. -parent: in nested frames, it loads window that contain hyperlink tag -top: loads document into full display area replaying current frame layout. <a href = Links.html target=_self> links </a>
JDBC Java Database Connectivity JDBC is used for accessing databases from Java applications Information is transferred from relations to objects and vice-versa JDBC Architecture
Java code calls JDBC library JDBC loads a driver Driver talks to a particular database An application can work with several databases by using all corresponding drivers Ideal: can change database engines without changing any application code (not always in practice Seven Steps of JDBC 1. Load the driver 2. Define the connection URL 5. Execute a query using statement 3. Establish the connection 6. Process the result 4. Create a Statement object 7. Close connection. Registering driver: Driver driver = new oracle.jdbc.OracleDriver(); DriverManager.registerDriver(driver); Class.forName("oracle.jdbc.driver.OracleDriver");
Connecting to the Database Connection con = DriverManager. getConnection(URL, user, pwd); o URL = jdbc:oracle:thin:@localhost:1521:xe o user = the user name of Oracle database o pwd = the password of the user of the database We use Statement objects in order to Query the database Update the database Three different interfaces are used: Statement, PreparedStatement, CallableStatement ExecuteQuery method returns a ResultSet object representing the query result executeUpdate returns the number of rows modified ExecuteUpdate is used for data manipulation: insert, delete, update, create table, etc. (anything other than querying!) ResultSet objects provide access to the tables generated as results of executing a Statement queries A ResultSetMetaData is an object that can be used to get information about the properties of the columns in a ResultSet object Prepared Statements are used for queries that are executed many times o e.g. PreparedStatement pstmt = con.prepareStatement(queryStr); o String deleteStr = DELETE FROM Items " + "WHERE Name = ? and Cost > ?"; o PreparedStatement pstmt = con.prepareStatement(deleteStr); o A ? can only be used to represent a column value Remember to close the connection con.close(); stmt.close(); pstmt.close(); rs.close() JSP CODES calculator code:Page one html
<html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> </head> <body> <div><h1>Calculator</h1></div> <form action="calculator.jsp" method="post"> <p>Number 1 <input type="text" name="num1"></p> <p>Number 2 <input type="text" name ="num2"></p> <p><input type="submit" value="Calculate"> </p> </form> </body> </html> Page two jsp <%@page contentType="text/html" errorPage="sorry.jsp" pageEncoding="UTF-8"%> <!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title> JSP Page</title> <% String n1,n2; n1 = request.getParameter("num1"); n2 = request.getParameter("num2"); double num1,num2; num1 = Double.parseDouble(n1); num2 = Double.parseDouble(n2) %> </head> <body> <h1>The result is: </h1> <h2> <%= n1%> + <%= n2 %> = <%= num1 + num2 %></h2> <h2> <%= n1%> - <%= n2 %> = <%= num1 - num2 %></h2> <h2> <%= n1%> x <%= n2 %> = <%= num1 * num2 %></h2> <h2> <%= n1%> / <%= n2 %> = <%= num1 / num2 %></h2> <h2> <%= n1%> % <%= n2 %> = <%= num1 % num2 %></h2> <%@include file = "footer.html" %> </body> </html>
<p><form action="CustomerRegistration.jsp"> <p> First Name : <input type="text" name="fname"> <p> Second Name:<input type="text"name="sname"> <p> Last Name :<input type="text" name="lname"> <p> Age:<input type="text" name="age"> <p> <input type="submit" value="Register"> <input type="reset" value="Clear"> </form> </body></html>
CustomerRegistration.jsp:
<html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title> JSP Page </title> </head> <body> <% String fn, sn, ln, ag; fn= request.getParameter("fname"); sn= request.getParameter("sname"); ln=request.getParameter("lname"); ag=request.getParameter("age"); %> <h2>Thank you <%= fn%> for registering </h2> <h4> the data that we have receive are as follows</h4> <%= fn %> <br> <%= sn %> <br> <%= ln %> <br> <%= ag %> </body> </html>
code for connecting Oracle:1. 2. 3. 4. 5. Class.forName("oracle.jdbc.driver.OracleDriver"); String url="jdbc:oracle:thin:@localhost:1521:xe"; Connection con = DriverManager.getConnection(url,"hr","hr"); Statement st = con.createStatement(); String sqlStr ="insert into tableName values(?,?,?,?,?,?,?,?,?,?)";
HTTP (hyper text transfer protocol) URN: is Universal Resource Name Independent of a specific location
URL: is Universal Resource Location URI : is either a URN or a URL Web Server: is an implementation of HTTP (either HTTP/1.0 or HTTP/1.1) User Agent: (UA) is a client (e.g., browser) Origin Server is the server that has the resource that is requested by a client Proxy acts on behalf of a client Reverse Proxy acts on behalf of a server Proxy Caches reduce latency for a given user agent if they can serve the request from their cache A UA sends a request and gets back a response HTTP 1.0 defines 16 headers None is required HTTP 1.1 defines 46 headers The Host header is required in all requests GET returns the content of a resource HEAD only returns the headers POST sends data to the given URI OPTIONS requests information about the communication options available for the given URI, such as supported content types PUT replaces the content of the given URI or generates a new resource at the given URI if none exists DELETE deletes the resource at the given URI TRACE invokes a remote loop-back of the request Status Codes in Responses
1xx indicates an informational message 2xx indicates success of some kind 3xx redirects the client to another URL 4xx indicates an error on the client's part 5xx indicates an error on the server's part