- Write a JSP page which uses tags available from the standard tag library JSTL
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jst1/core" %>
<html>
<head>
<title>JSTL TAGs</title>
</head>
<body>
<h4><code><c:set> and <c:remove> Tags</code></h4>
<c:set var="date" value="<%=new java.util.Date()%>" scope="request">
</c:set>
Today's Date:<c:out value="${date}" />
<c:remove var="date" />
Date after using
<c:remove />
<c:out value="${date}" />
</br>
<h4> <code> <c:if>, <c:forToken>,<c:forEach>, <c:choose> and <c:when> Tags</code></h4>
<c:forToken var="item" items="< once ) Upon , A ( Time % there..>" delims="<),(%.>">
<ul>
<c:forEach var="i" begin="1" end="10">
<li>
i=${i}
<c:if test="$(i == 2)"> Value is Equal 2 </c:if>
<c:choose>
<c:when test="${i < 3}">less then 3</c:when>
<c:when test="${i < 5}">less then 5</c:when>
<c:otherwise>Value is Greater then 3 or 5</c:otherwise>
</c:choose>
</li>
</c:foreach>
</ul>
<h4> <code> <c:catch> Tags</code></h4>
<c:catch var="x">
<% int x=1/0;%>
</c:catch>
</body>
</html> - Write A Servlet which uses the concept of Request forwarding & including external source in the current servlet context.
Servletforward :
import java.io.*;
import javax.servlet.http.*;
import javax.servlet.*;
public class servletforward extends HttpServlet
{
public void doGet(HttpServletRequest req,HttpServletResponse res)throws IOException,ServletException
{
String address = "/servletinclude";
RequestDispatcher dispatcher = req.getRequestDispatcher(address);
dispatcher.forward(req, res);
}
}
ServletInclude ::
import java.io.*;
import javax.servlet.http.*;
import javax.servlet.*;
public class servletinclude extends HttpServlet
{
public void doGet(HttpServletRequest req,HttpServletResponse res)throws IOException,ServletException
{
String header="/header.jsp";
String footer="/footer.jsp";
res.setContentType("text/html");
PrintWriter out=res.getWriter();
out.println("<html><body><center><table border=2><tr>\n"+
"<td>");
RequestDispatcher dispatcher1 =req.getRequestDispatcher(header);
dispatcher1.include(req, res);
out.println("</td></tr><tr><td><h2>hello friends welcome</h2></td></tr>");
out.println("<tr>\n"+
"<td>");
RequestDispatcher dispatcher2 =req.getRequestDispatcher(footer);
dispatcher2.include(req, res);
out.println("</td></tr></table></body></html>");
}
} - Develop a JSP Page to display the personal information and result information of the student in two different tabular formats.
<html>
<head>
<title>Ex33</title>
</head>
<body>
<%@page import="java.sql.*" %>
<%
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con = DriverManager.getConnection("JDBC:ODBC:DATASOURCE");
Statement s=con.createStatement();
s.executeQuery("Select * from stud");
ResultSet rs=s.getResultSet();
rs.next();
%>
<table align="center" width="100%" height="70%">
<tr>
<td>
<table align="center" width="60%" height="50%" border="1">
<tr bgcolor="#CCCCCC"><th colspan="2" align="left"><b>Student's Personal Information</b></th></tr>
<tr><td>Name</td><td><%=rs.getString("name")%></td></tr>
<tr><td>Enrollment Number</td><td><%=rs.getString("EnrollNum")%></td></tr>
<tr><td>Date Of Birth</td><td><%=rs.getString("DOB")%></td></tr>
<tr><td>Address</td><td><%=rs.getString("Address")%></td></tr>
<tr><td>Gender</td><td><%=rs.getString("Gender")%></td></tr>
<tr><td>Contact Number</td><td><%=rs.getString("cellnum")%></td></tr>
</table>
</td>
<td>
<table align="center" width="60%" height="50%" border="1">
<tr bgcolor="#CCCCCC"><th colspan="2" align="left"><b>Result of Semester 3</b></th></tr>
<tr><td>JAVA</td><td><%=rs.getString("JAVA")%></td></tr>
<tr><td>SS</td><td><%=rs.getString("SS")%></td></tr>
<tr><td>SM</td><td><%=rs.getString("SM")%></td></tr>
<tr><td>OS</td><td><%=rs.getString("OS")%></td></tr>
<tr><td>SOOADM</td><td><%=rs.getString("SOOADM")%></td></tr>
</table>
</td>
</tr>
</table>
<% }
catch(Exception e)
{%>
Exception generated. Description<%=e%>
<%}%>
</body>
</html> - Develop a JSP Page to perform database driven operations like insert, Delete, Update and selection with table named Student having fields like StudId, Name, and Address result.
<html>
<body>
<title>
Tutorial 7 Pogram-1(AddressBook)
<title>
<center><h3>My AddressBook</h3></center>
<form method=get>
<table align=center>
<tr><td>Student Id <input type=text name="id" value=<% if(request.getParameter("up")!=null) { out.println(request.getParameter("uid"));}%>></td></tr>
<tr><td>Student Name <input type=text name="name" value=<% if(request.getParameter("up")!=null) { out.println(request.getParameter("uname"));}%>></td></tr>
<tr><td>Address <input type=text name="addr" value=<% if(request.getParameter("up")!=null) { out.println(request.getParameter("uaddr"));}%>></td></tr>
<tr colspan=3 align=center><td><input type="submit" name=<% if(request.getParameter("up")!=null) { out.println("updat");} else {out.println("add");}%> value=<% if(request.getParameter("up")!=null) { out.println("Update");} else {out.println("ADD");}%>>
<input type="submit" name="dis" value="Display"></td></tr>
</table>
</form>
</body>
</html>
<%@ page import="java.sql.*" %>
<%@ page import="java.util.*" %>
<%
Connection cn=null;
String q=null;
ResultSet rs=null;
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
cn=DriverManager.getConnection("jdbc:odbc:DRIVER={Microsoft Access Driver (*.mdb)};DBQ=D:\\tomcat7\\webapps\\jsp\\34\\student_info.mdb","","");
Statement statement = cn.createStatement();
if(request.getParameter("add")!=null)
{
try
{
q="INSERT INTO student VALUES('"+request.getParameter("id").toString().trim()+"','" +
request.getParameter("name").toString().trim() + "','" +
request.getParameter("addr").toString().trim()+"')";
int a=statement.executeUpdate(q);
if (a>0)
{
out.println("Successfully inserted");
}
else
{
out.println("Not inserted");
}
}
catch(SQLException e)
{
out.println(e.toString());
}
}
if(request.getParameter("dis")!=null)
{
String uid,uname,uaddr;
q="SELECT * FROM student";
rs = statement.executeQuery(q);
if(rs.next())
{
%>
<table border=0 align="center">
<tr>
<td>STUDENT ID</td>
<td>NAME</td>
<td>ADDRESS</td>
</tr>
<%
while(rs.next())
{
uid=rs.getString(1);
uname=rs.getString(2);
uaddr=rs.getString(3);
out.println("<tr>");
out.println("<td>"+uid+</td>");
out.println("<td>"+uname+</td>");
out.println("<td>"+uaddr+</td>");
out.println("<td><a href=addressbook.jsp?uid="+uid+"&up=dd&uaddr="+uaddr+"&uname="+uname+">Update</a></td>");
out.println("<td>"<a href=addressbook.jsp?uid="+uid+"&del=ddd&uaddr="+uaddr+"&uname="+uname+">Delete</a></td>");
out.println("</tr>");
}%>
</table>
<%
}
else
{
out.println("Record not found");
}
}
if(request.getParameter("updat")!=null)
{
try
{
q="UPDATE student SET name='"+request.getParameter("name")+"',address='"+request.getParameter("addr")+"' where id='"+request.getParameter("id")+"'";
int bb=statement.executeUpdate(q);
if (bb>0)
{
out.println("<center>Successfully updated</center>");
}
else
{
out.println("Not updated");
}
}
catch(SQLException e)
{
out.println(e);
}
}
if(request.getParameter("del")!=null)
{
try
{
q="DELETE FROM student WHERE id='"+request.getParameter("uid")+"'";
int bb=statement.executeUpdate(q);
if (bb>0)
{
out.println("<center>Successfully deleted</center>");
}
else
{
out.println("Not deleted");
}
}
catch(SQLException e)
{
out.println(e);
}
}
%> - Write a JSP page to use JSP’s Page Directives.
<html>
<head>
<title>Use Of Jsp Page Directive</title>
</head>
<body>
<h2>The Import Attribute</h2>
<%@ page import="java.util.*" %>
Today's Date is :: <%= new Date() %>
<%@ page contentType="application/vnd.ms.excel" %>
<table border=1>
<tr>
<th>Item</th>
<th>Price</th>
</tr>
<tr>
<td>TV</td>
<td>6000</td>
</tr>
<tr>
<td>TV</td>
<td>6000</td>
</tr>
</table>
<%@ page session="true" %>
</body>
</html> - Write a JSP page to use JSP Scripting.
<html>
<head>
<title>Scriplet Tag Example</title>
</head>
<%
String bgcolor=request.getParameter("bgcolor");
if((bgcolor == null) || (bgcolor.trim().equals("")))
{
bgcolor="WHITE";
}
%>
<body bgcolor="<%= bgcolor %>">
<center>
<H2>Testing BackGround Color = "<%= bgcolor %>" </h2>
</center>
</body>
</html> - Write a JSP Page to which uses Session Tracking for online shopping
Available Soon.....
BACK |
Prepared By:
Student of B. H. Gardi College of Eng. & Tech., MCA Department
(Nisarg Juthani, Kajal Savjani, Desai Paresh, Ramoliya Nilesh, Thanki Ravi.....)
No comments:
Post a Comment