For this program you have to
write web.xml file and put it in the WEB-APPS folder under your application
folder
import java.io.*;
import java.sql.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class
OnlineFeedBackForm extends HttpServlet
{
int c1=0,c2=0,c3=0;
int N=0;
public void doGet(HttpServletRequest
req,HttpServletResponse res)throws ServletException,IOException
{
int count[]=new int[100];
PrintWriter out=res.getWriter();
res.setContentType("text/html");
String t1=req.getParameter("t1");
String t2=req.getParameter("t2");
String t3=req.getParameter("t3");
String t4=req.getParameter("t4");
int i=0;N++;
int
v1=Integer.parseInt(req.getParameter("v1"));
count[i++]=v1;
int
v2=Integer.parseInt(req.getParameter("v2"));
count[i++]=v2;
int
v3=Integer.parseInt(req.getParameter("v3"));
count[i++]=v3;
int v4=Integer.parseInt(req.getParameter("v4"));
count[i++]=v4;
int
v5=Integer.parseInt(req.getParameter("v5"));
count[i++]=v5;
int
v6=Integer.parseInt(req.getParameter("v6"));
count[i++]=v6;
int
v7=Integer.parseInt(req.getParameter("v7"));
count[i++]=v7;
int v8=Integer.parseInt(req.getParameter("v8"));
count[i++]=v8;
int
v9=Integer.parseInt(req.getParameter("v9"));
count[i++]=v9;
int
v10=Integer.parseInt(req.getParameter("v10"));
count[i++]=v10;
int
v11=Integer.parseInt(req.getParameter("v11"));
count[i++]=v11;
int v12=Integer.parseInt(req.getParameter("v12"));
count[i++]=v12;
int
v13=Integer.parseInt(req.getParameter("v13"));
count[i++]=v13;
int
v14=Integer.parseInt(req.getParameter("v14"));
count[i++]=v14;
int
v15=Integer.parseInt(req.getParameter("v15"));
count[i++]=v15;
int
v16=Integer.parseInt(req.getParameter("v16"));
count[i++]=v16;
int
v17=Integer.parseInt(req.getParameter("v17"));
count[i++]=v17;
int
v18=Integer.parseInt(req.getParameter("v18"));
count[i++]=v18;
int
v19=Integer.parseInt(req.getParameter("v19"));
count[i++]=v19;
int
v20=Integer.parseInt(req.getParameter("v20"));
count[i++]=v20;
int
v21=Integer.parseInt(req.getParameter("v21"));
count[i++]=v21;
int
v22=Integer.parseInt(req.getParameter("v22"));
count[i++]=v22;
int
v23=Integer.parseInt(req.getParameter("v23"));
count[i++]=v23;
int
v24=Integer.parseInt(req.getParameter("v24"));
count[i++]=v24;
/*
int temp;
for(int a=0;a<23;a++)
for(int l=a+1;l<24;l++)
{if(count[a]>count[l])
{ temp=count[a];
count[a]=count[l];
count[l]=temp;
}
}*/
for(int t=0;t<24;t++)
switch(count[t])
{
case
1:c1++;break;
case 2:c2++;break;
case 3:c3++;break;
}
int X1=3;int X2=2;int X3=0;
double
per=(((c1*X1)+(c2*X2)+(c3*X3))*100)/(3*N);
//st.executeUpdate("insert into t1
values('"+t1+"','"+t2+"','"+t3+"')");
out.println("<html>");
out.println("<body
bgcolor=chocolate>");
out.println("<center>");
out.println("<font
color=white>");
out.println("<marquee><h1>E9:
ENGINEERING COLLEGE :: CHIRALA</h1></marquee>");
out.println("<h2>STUDENT
FEEDBACK FORM</h2>");
out.println("<table
border=1>");
out.println("<tr>");
out.println("<td>NAME");
out.println("</td>");
out.println("<td>SUBJECT");
out.println("</td>");
out.println("<td>YEAR
OF STUDY");
out.println("</td>");
out.println("<td>SEMISTER");
out.println("</td>");
out.println("<td>EXECELENT");
out.println("</td>");
out.println("<td>GOOD");
out.println("</td>");
out.println("<td>POOR");
out.println("</td>");
out.println("<td>PERCENTAGE");
out.println("</td>");
out.println("</tr>");
out.println("<tr>");
out.println("<td
align=center>"+t1);
out.println("</td>");
out.println("<td
align=center>"+t2);
out.println("</td>");
out.println("<td
align=center>"+t3);
out.println("</td>");
out.println("<td
align=center>"+t4);
out.println("</td>");
out.println("<td
align=center>"+c1);
out.println("</td>");
out.println("<td
align=center>"+c2);
out.println("</td>");
out.println("<td
align=center>"+c3);
out.println("</td>");
out.println("<td
align=center>"+per);
out.println("</td>");
out.println("</tr>");
out.println("</font>");
out.println("</table>");
out.println("</body>");
out.println("</html>");
}//service()
}//class
THIS IS A SAMPLE SERVELT PROGRAM
WHICH IS THE TYPE OF HTTP SERVLET
To execute this program you have to
install one of the web servers i.e. like javawebserver (JWS), apache-tomcat or Geronimo
web logic web sphere glassfish IIS jboss etc
Set classpath to jdk
Path to servlet-api.jar and
define JAVA_HOME Catalina_home one to bin and another one is to lib
Drop this class according to servlet
design architecture ,previous servlet engine latest servlet container
//concept-2 httpservlet
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class MultiplyServlet extends
HttpServlet
{
public
void init() throws ServletException
{
System.out.println("MultiplyServlet
: init()");
}
public
void destroy()
{
System.out.println("MultiplyServlet
: destroy()");
}
protected void doGet(
HttpServletRequest request,HttpServletResponse response) throws
ServletException,IOException
{
doPost(
request, response );
}
protected void
doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException,IOException
{
response.setContentType("text/html");
ServletOutputStream
out = response.getOutputStream();
int
a = Integer.parseInt(request.getParameter("n1"));
int
b = Integer.parseInt(request.getParameter("n2"));
out.println("<html>");
out.println("<body>");
out.println("<table
align='center' border='1'>");
for(int
i=1; i<=b; i++)
{
out.println("<tr>");
out.println("<td><h2>"
+ a + "*" + i + "</td>");
out.println("<td><h2>"
+ (a * i)+ "</td>");
out.println("</tr>");
}
out.println("</table>");
out.println("</body>");
out.println("</html>");
out.flush();
}
}
కామెంట్లు లేవు:
కామెంట్ను పోస్ట్ చేయండి