Download as txt, pdf, or txt
Download as txt, pdf, or txt
You are on page 1of 3

NAME=ROHAN CHAUDAR

ROLL NO=54073
EX_4
A1}
<% page language="java" import="java.util.*; import java.io.*; import java.text.*;"
%>

<html>
<body>
<h1>Welcome</h1>
<%
Date d=new Date();
SimpleDateFormat sdf=new SimpleDateFormat();
String strPattern="E MMMM dd hh:mm:ss z yyyy";
out.println("Current Date and Time--> "+sdf.format(d));
out.println("<br>");

String userAgent=request.getHeader("User-Agent");
out.println("Request user Agent--> "+userAgent);
out.println("<br>");
%>
<%
Cookie[] cookies=request.getCookies();
boolean foundCookie=false;
if(!foundCookie)
{
Cookie c=new Cookie("color","red");
response.addCookie(c);
out.println("Cookie added..");
out.println("<br>");
}
%>
<%
String s=config.getInitParameter("city");
out.println("City Init Param Value->> "+s);
out.println("<br>");
%>
<%
String s1=application.getInitParameter("state");
out.println("State Context Param Value->> "+s1);
out.println("<br>");
%>
<%=this.getServletInfo()%>
</body>
</html>

A2}
<%
String ext=request.getParameter("fname");
File f=new File("../webapps/jsp_examples/temp");
String fn[]=f.list();
for(i=0;i<fn/length;i++)
{
File f1=new File(f+"//" +fn[i]);
if((f1.isFile() && fn[i].endsWith(ext)))
out.println("<br><a href="tfn[i]+">"+fn[i]+"</a>");
}
%>
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<%@ page import="java.util.*"%>
<%! String name=" ";%>

<html>
<body>
<form action="Seta2.jsp" method="POST">
Enter File Extension :<input type="text" name="fname">
<input type="Submit" value="send">
</form>
</body>
</html>
<%@ page language="java" import="java.io.*;"%>

B1}
<html>
<head>
<meta http-equiv="Content-Type" content="text/html charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
<form action="b1.jsp" method="GET">
Enter Name : <input type=text name="name">
<br>
<input type=submit value="Submit" name="submit">
</form>

<%String submit=request.getParameter("submit");
name=request.getParameter("name");
if(submit!=null)
{
Date d=new Date();
if(d.getHours()<12)
{
%>
Good Morning,
<%
}
else if(d.getHours()<17)
{
%>
Good Afternoon,
<%
}
else
{
%>
Good Evening,
<%
}
%>
<%
}
if(name.length()!=0)
out.print(name);
%>
</body>
</html>

B2}
<html>
<head>
<title>MCQ</title>
</head>
<%@page import="java.sql.*, java.util.*"%>
<%! Connection con=null; Statement st; ResultSet rs=null; LinkedList ll; Random
r;String s;int No;%>
<%!
public void jspInit()
{
r=new Random();
ll=new LinkedList();
try{
Class.forName("org.postgresql.Driver");

con=DriverManager.getConnection("jdbc:postgresql://192.168.0.254/testty54073,ty5407
3,modern");

st=con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);
rs=st.executeQuery("select * from mcq");
rs.last();
No=rs.getRow();
}
catch(Exception e)
{
e.printStackTrace();
}
}
%>
<body>
<font size="22">
<%
if(session.isNew()==true)
session.setAttribute("score","0");
int no=-1;
String ans=resquest.getParameter("ans");
String choice=resquest.getParameter("choice");
s=request.getParameter("Submit");
%>

You might also like