8
ASSIGNMENT -2 JAVA AND WEB TECHNOLOGIES (JWT) PRESENTED BY: Sruthi.k 14691D5820 M.Tech CSE MITS. PRESENTED To: S.Vikram Phaneendra M.Tech, Assistant Professor, CSE Department. MADANAPALLE INSTITUTEOF TECHNOLOGY AND SCIENCE

NAG JWT-2

Embed Size (px)

DESCRIPTION

lbl

Citation preview

Page 1: NAG JWT-2

ASSIGNMENT -2

JAVA AND WEB TECHNOLOGIES (JWT)

PRESENTED BY:Sruthi.k14691D5820M.Tech CSE MITS.

PRESENTED To:S.Vikram Phaneendra M.Tech,

Assistant Professor,CSE Department.

DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING (Approved by AICTE, New Delhi and Affiliated to J.N.T.U, Anantapur)

Madanapalle, Chittoor(Dist.), A.P.

MADANAPALLE INSTITUTEOF TECHNOLOGY AND SCIENCE

Page 2: NAG JWT-2

1. To write a servlet program print percentage of student. accepts the six subjects marks through HTML page.

2. In detailed explain error handling mechanism using JSP

Problem statement: write a servlet program that prints percentage of student .accepts the six subjects’ marks through html page.Explanation:Servlet originality is utilize to create web application (lives at server side and produces element website page).Servlet innovation is powerful and adaptable in light of java dialect. Before servelt, CGI (Common Gateway Interface) scripting dialect was major as a server-side programming dialect. In any case, there was frequent inconvenience of this innovation. We have examined these detriments underneath. There are numerous interfaces and classes in the servlet API, for example, Servlet, Generic Servlet, Http Servlet, Servlet Request, Servlet Response and so on.

Servlet can be depicted from numerous points of view dependent up on the connection.

• It is and proceeds i.e. used to make web applications.

• API that gives frequent interface and classes include documentations.

• servlet is an interface that must be executed for making any servlet.• Servlet is a web segment that is sent on the server to make elementProgram: Student details.html:<htmll><head studemt details><title student details></title></head><body><from name=”form1” method=”GET” acion=”/q1/try1.do”><br><h1>student marks</h1><br>enter marks for student 1:<input type=text name=stud1><br><br>enter marks for student 2:<input type=text name=stud2><br><br>enter marks for student 3:<input type=text name=stud3><br><br>enter marks for student 4:<input type=text name=stud4><br><br>enter marks for student 5:<input type=text name=stud5><br><br>enter marks for student 6:<input type=text name=stud6><br><br>enter marks for student 7:<input type=text name=stud7><br><br>enter marks for student 8:<input type=text name=stud8><br><br>enter marks for student 9:<input type=text name=stud9><br><br><input type=submit value=SUBMIT></from></body></html>Student details.java:

Page 3: NAG JWT-2

Import java.io.*;Import java.util.*;Import javax.servlet.*;Import javax.servlet.http.*;Public class student extends HttpServlet{Public void do get(httpservlet request req,httpservlet response res) throwa IOExceptionservletexception{Print write out=reg.getwrite(); Int s1, s2, s3, s4, s5, s6, s7, s8, s9, s10;Double p []=newdoublep[10];Int first-0, second=0, third=0;Out.write{“html”);Out.write(“<head>”);Out.write(“title”);Out.write(“</title>”);Out.write(“<body>”);

out.write("<h1>Results</h1><br><br>"); s1=Integer.parseInt(req.getParameter("stud1")); p[0]=((100*s1)/400); s2=Integer.parseInt(req.getParameter("stud2")); p[1]=((100*s2)/400); s3=Integer.parseInt(req.getParameter("stud3")); p[2]=((100*s3)/400); s4=Integer.parseInt(req.getParameter("stud4")); p[3]=((100*s4)/400); s5=Integer.parseInt(req.getParameter("stud5")); p[4]=((100*s5)/400); s6=Integer.parseInt(req.getParameter("stud6")); p[5]=((100*s6)/400); s7=Integer.parseInt(req.getParameter("stud7")); p[6]=((100*s7)/400); s8=Integer.parseInt(req.getParameter("stud8")); p[7]=((100*s8)/400); s9=Integer.parseInt(req.getParameter("stud9")); p[8]=((100*s9)/400); s10=Integer.parseInt(req.getParameter("stud10")); p[9]=((100*s10)/400); for(int i=0; i<10; i++) { if(p[i-1]>=70.0) { out.write("Student "+i+" : First Class"); first++; } elseif(p[i-1]>=60.0) { out.write("Student "+i+" : Second Class"); second++; } elseif(p[i-1]>=45.0) { out.write("Student "+i+" : Third Class"); third++; }

Page 4: NAG JWT-2

out.write("<br><br>"); } out.write("<br><br>"); out.write("Total of First Class :" + first); out.write("<br><br>"); out.write("Total of Second Class :" + second); out.write("<br><br>"); out.write("Total of Third Class :" + third); out.write("</body>"); out.write("</html>"); out.close(); } }

2)Error handling mechanism using JSP:

Exception Handling is a method of taking care of significant situation that may ensue in your application. Exemption Handling in JSP is much less difficult than Java Technology special case taking care of. Although the fact that JSP Technology also utilizes the same special case class object.

It is truly clear that you don’t need to show slip stack follow to the gentleman surfing your site. You can't keep all mistakes in your application however you can at least give a client friendlier slip reaction page.

Approaches to perform special case taking care of in JSP

JSP give two diverse approach to perform special case taking care of.

1. Using is Error Page and error Page possessions of page mandate.

2. Using <error-page> tag in Deployment Descriptor.

Illustration of is Error Page and error Page characteristic is Error Page property in page mandate formally select a JSP page as a mistake page.

error.jsp

errorPage quality in page order tells the Web Container that if a special case happen in this page, forward the solicitation to a slip page.

sum.jsp

Proclaiming lapse page in Deployment Descriptor You can likewise proclaim lapse pages in the DD for the whole Web Apllication.Using <error-page> tag in Deployment Descriptor you can even arrange diverse mistake pages for distinctive special case sorts, or HTTP blunder code type(400,500 and so on.).

Proclaiming a lapse page for all sort of special case

Page 5: NAG JWT-2

<error-page>

<exception-type>java.lang.Throwable</exemption type>

<location>/error.jsp</location>

</lapse page>

Proclaiming a lapse page for more itemized special case

<error-page>

<exception-type>java.lang.ArithmeticException</exemption type>

<location>/error.jsp</location>

</lapse page>

Proclaiming a mistake page taking into account HTTP Status code

<error-page>

<error-code>404</lapse code>

<location>/error.jsp</location>

</lapse page>

Standard Tag(Action Element)

JSP determination gives Standard(Action) labels for utilization inside of your JSP pages. These labels are utilized to expel or take out scriptlet code from your JSP page in light of the fact that scriplet code are in fact not suggested these days. It's thought to be terrible practice to put java code specifically inside your JSP page.

Standard labels start with the jsp: prefix. There are numerous JSP Standard Action label which are utilized to perform some particular undertaking.

The accompanying are some JSP Standard Action Tag accessible:

Activity Tag Description

jsp:forward forward the solicitation to another page

jsp:getProperty retrieve a property from a JavaBean occurrence.

jsp:include include the runtime reaction of a JSP page.

jsp:plugin Generates customer program particular build that makes an OBJECT or EMBED tag for the Java Applets

Page 6: NAG JWT-2

jsp:element Defines XML components alertly

jsp:attribute defines alertly characterized XML component's property

jsp:param Adds parameters to the solicitation

jsp:fallback Supplies interchange content if java applet is distracted on the customer

jsp:body Used inside of standard or custom labels to supply the label body.

jsp:text Use to compose format content in JSP pages and reports.

jsp:setProperty store information in JavaBeans case. jsp:useBean instantiates a JavaBean