Creation of Dynamic Content in Web Application Using JSP
Creation of Dynamic Content in Web Application Using JSP
Roll No:
Date:
___________
Faculty: ___________
Roll No:
Date:
___________
Faculty: ___________
Beans.jsp:<%@ page import="user.MarksBean" %> <jsp:useBean id="marksbean" scope="page" class="user.MarksBean"> <jsp:setProperty name="marksbean" property="username" value='<%=request.getParameter("username") %>'/> <jsp:setProperty name="marksbean" property="mark1"/> <jsp:setProperty name="marksbean" property="mark2"/> </jsp:useBean> <html> <head> <title>Percentage</title> </head> <body> <p>Welcome: <jsp:getProperty name="marksbean" property="username"/> </p> <p>Your marks are :<br/> DAA:<jsp:getProperty name="marksbean" property="mark1"/><br/> DBMS:<jsp:getProperty name="marksbean" property="mark2"/> </p><br/> <p>Your Percentage is <%= marksbean.getCalculateper() %> </p><br /> <p>Comments on your percentage is <%= marksbean.getComments() %> </p> </body> </html>
Roll No:
Date:
___________
Faculty: ___________
Web.xml
<?xml version="1.0" encoding="ISO-8859-1"?> <!--<!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN" "http://java.sun.com/dtd/web-app_2_3.dtd"> --> <web-app> </web-app>
Roll No:
Date:
___________
Faculty: ___________
MarksBean.java:package user; import java.io.*; public class MarksBean { String username=""; String mark1="",mark2=""; int tot; public MarksBean() { } public void setUsername(String userName) { this.username=userName; } public String getUsername() { return this.username; } public void setMark1(String mark1) { this.mark1=mark1; } public String getMark1() { return mark1; } public void setMark2(String mark2) { this.mark2=mark2; } public String getMark2() { return mark2; } public int getCalculateper()throws IOException { tot=((Integer.parseInt(mark1))+(Integer.parseInt(mark2)))/2;
Roll No:
Date:
___________
Faculty: ___________
return tot; } public String getComments() { if(tot>=75) return "You passed with distinction"; else if(tot>=60 && tot<75) return "You passed in first class"; else return " You passed in second class"; } }
Roll No:
Date:
___________
Faculty: ___________
Roll No:
Date:
___________
Faculty: ___________
<center> <% if(IsPostBack) { Response.Write("Welcome " +Name.Text+ " !!!\n"); var total = System.Convert.ToInt32(DBMS.Text) + System.Convert.ToInt32(DAA.Text); Response.Write("Your Total is " + total); } %> </center> </body> </html>
Roll No:
Date:
___________
Faculty: ___________
9.PROVIDING DATA STORE SUPPORT FOR WEB SITE USING JDBC. Login.html:<html> <head> <title>Login</title> </head> <h1> <center>Enter Details</center> </h1> <body> <form action="http://localhost:9090/JDBC/insertdata.jsp"> <center> <table> <tr> <td>Name</td> <td><input type="text" name="name"></td> </tr> <tr> <td>Address</td> <td><input type="text" name="address"></td> </tr> </table> </center> <br/> <center> <input type="submit" name="submit" value="Submit"/> </form> </center> </body> </html>
Roll No:
Date:
___________
Faculty: ___________
insertdata.jsp:<%@page import="java.sql.*"%> <% String name=request.getParameter("name"); String address=request.getParameter("address"); try { Class.forName("oracle.jdbc.driver.OracleDriver"); Connection con=DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:XE","system","sriya"); Statement st=con.createStatement(); int i=st.executeUpdate("insert into data1 values ('"+name+"','"+address+"')"); con.close(); out.println("<html><head><title>Successfull</title></head>"); out.println("<h1><center>Successful</center></h1><body><center><p>Data Inserted Succesfully</p></center>"); out.println("</body></html>"); } catch(Exception e) { System.out.println(e); } %>