0% found this document useful (0 votes)
55 views

Creation of Dynamic Content in Web Application Using JSP

The document describes creating dynamic web content using Java Server Pages (JSP). It includes code for: 1. A homepage with a form to collect user input like name, marks for two subjects. This form submits to a JSP page. 2. A JSP page that uses a JavaBeans component to display the user input and calculate percentage. 3. The JavaBeans component code to set/get user input and calculate percentage. It also provides code for connecting a web application to a database using JDBC to insert user details into a table.

Uploaded by

Aneesha Reddy
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
55 views

Creation of Dynamic Content in Web Application Using JSP

The document describes creating dynamic web content using Java Server Pages (JSP). It includes code for: 1. A homepage with a form to collect user input like name, marks for two subjects. This form submits to a JSP page. 2. A JSP page that uses a JavaBeans component to display the user input and calculate percentage. 3. The JavaBeans component code to set/get user input and calculate percentage. It also provides code for connecting a web application to a database using JDBC to insert user details into a table.

Uploaded by

Aneesha Reddy
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 9

Stanley College of Engineering & Technology for Women

Chapel Road, Hyderabad

Roll No:

1 6 0 6 1 0 7 3 3 1 1 2 Exp No: ____ _

Date:

___________

Page No: ____________________

Faculty: ___________

7. CREATION OF DYNAMIC CONTENT IN WEB APPLICATION USING JSP.


HOMEPAGE:--- (task_jsp.html)
<html> <head> <title>Student Percentage Calculator</title> </head> <body> <center> <h2>Welcome to III Yr I-sem Percentage Calculator</h2> <form method="POST" action="http://localhost:9090/jsp_task/beans.jsp"> <table> <tr> <td> UserName </td > <td> <input type="text" name="username"/> </td> </tr> <tr> <td> Password </td > <td> <input type="password" name="password"/> </td> </tr> <p>Enter Marks</p><br/> <tr> <td>DAA</td> <td><input type="text" name="mark1"/></td> </tr> <tr> <td>DBMS</td> <td><input type="text" name="mark2"/></td> </tr> </table> <input type="submit" name="submit" value="calculate"/> </form> </center> </body> </html>

Stanley College of Engineering & Technology for Women


Chapel Road, Hyderabad

Roll No:

1 6 0 6 1 0 7 3 3 1 1 2 Exp No: ____ _

Date:

___________

Page No: ____________________

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>

Stanley College of Engineering & Technology for Women


Chapel Road, Hyderabad

Roll No:

1 6 0 6 1 0 7 3 3 1 1 2 Exp No: ____ _

Date:

___________

Page No: ____________________

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>

Stanley College of Engineering & Technology for Women


Chapel Road, Hyderabad

Roll No:

1 6 0 6 1 0 7 3 3 1 1 2 Exp No: ____ _

Date:

___________

Page No: ____________________

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;

Stanley College of Engineering & Technology for Women


Chapel Road, Hyderabad

Roll No:

1 6 0 6 1 0 7 3 3 1 1 2 Exp No: ____ _

Date:

___________

Page No: ____________________

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"; } }

Stanley College of Engineering & Technology for Women


Chapel Road, Hyderabad

Roll No:

1 6 0 6 1 0 7 3 3 1 1 2 Exp No: ____ _

Date:

___________

Page No: ____________________

Faculty: ___________

8.CREATION OF DYNAMIC CONTENT IN WEB APPLICATION USING ASP.NET


Project Name:- reddy File Name:- myp
<%@ Page Language="C#" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <script runat="server"> </script> <html xmlns="http://www.w3.org/1999/xhtml"> <head id="Head1" runat="server"> <title>Details</title> </head> <center> <h1>Enter Marks Details</h1> </center> <body> <form id="form1" runat="server"> <center> <div> <br /><br /><br /> <asp:Label ID="Label1" runat="server" Text="Name"></asp:Label> <asp:TextBox ID="Name" runat="server"></asp:TextBox> <br /> <asp:Label ID="Label2" runat="server" Text="DBMS"></asp:Label> <asp:TextBox ID="DBMS" runat="server"></asp:TextBox> <br /> <asp:Label ID="Label3" runat="server" Text="DAA"></asp:Label> <asp:TextBox ID="DAA" runat="server"></asp:TextBox> <br /><br /> <asp:Button ID="Submit" runat="server" Text="Submit" /> <br /><br /> </div> </center> </form>

Stanley College of Engineering & Technology for Women


Chapel Road, Hyderabad

Roll No:

1 6 0 6 1 0 7 3 3 1 1 2 Exp No: ____ _

Date:

___________

Page No: ____________________

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>

Stanley College of Engineering & Technology for Women


Chapel Road, Hyderabad

Roll No:

1 6 0 6 1 0 7 3 3 1 1 2 Exp No: ____ _

Date:

___________

Page No: ____________________

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>

Stanley College of Engineering & Technology for Women


Chapel Road, Hyderabad

Roll No:

1 6 0 6 1 0 7 3 3 1 1 2 Exp No: ____ _

Date:

___________

Page No: ____________________

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); } %>

You might also like