You are on page 1of 7

1

1. Write a jsp program to design a Login Screen which checks the username and password. If valid then the user is allowed to login otherwise it should display some message. Login.jsp
<html> <head> <title>Enter your name and password</title> </head> <body bgcolor="#999966"> <p>&nbsp;</p> <form method="POST" action="loginaction.jsp"> <p><font color="#800000" size="5">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Enter your name:</font><input type="text" name="username" size="20"></p> <p><font color="#800000" size="5"> Enter your password:</font><input type="text" name="password" size="20"></p> <p><input type="submit" value="Submit" name="B1"></p> </form></body> </html>

Loginaction.jsp
<%@page contentType="text/html" %> <html> <body bgcolor="#999966"> <% String username = request.getParameter("username"); String password = request.getParameter("password"); out.println("Checking login<br>"); if (username == null || password == null) { out.print("Invalid paramters "); }

2
// Here you put the check on the username and password if (username.toLowerCase().trim().equals("akrati") && password.toLowerCase().trim().equals("123")) { %><p><font size="6">Welcome :&nbsp; <%=request.getParameter("username")%></font></p> <%session.setAttribute("username", username); } else { out.println("Invalid username and password"); } %> </body> </html>

2. Create a servlet that will return an html page to the client containing course details such as course name and course fees in a tabular format.
import java.io.*; import javax.servlet.*; import javax.servlet.http.*; public class CourseServ extends HttpServlet { public void doGet(HttpServletRequest req, HttpServletResponse res) throws IOException, ServletException { res.setContentType("text/html"); PrintWriter out = res.getWriter(); out.println("<html><head><title>Info</title></head>"); out.println("<body><center><table border = '1'>"); out.println("<th>Course Name</th>"); out.println("<th>Course Fees</th>"); out.println("<tr><td>core java</td><td>3000</td></tr>"); out.println("<tr><td>adv java</td><t d>5000</td></tr>"); out.println("</table></center>"); out.println("</body></html>"); } }

3. Write a java program to display actor (name, movie) details specified by the user using jsp Actor.jsp
<html> <head> <title>Enter the Details </title> </head> <body> <p>&nbsp;</p> <form method="POST" action="disp.jsp"> <h1>Welcome</h1> <p>Enter Actor name: <input type="text" name="fname" size="20"></p> <p>sEnter Movie: <input type="text" name="movie" size="20"></p> <p><input type="submit" value="Submit" name="B1"></p> </form> </body> </html>

Disp.jsp
<%@page contentType="text/html" %> <html> <body> <p><%=request.getParameter("fname")%></p>&nbsp; <p><%=request.getParameter("movie")%></p> </body> </html>

4. Create a html page which contains a list of colors and it should display the selected color in the next page using servlets also change the background with selected color.

5. Create a servlet that will count the number of times a client containing the webpage (use session tracking)
import import import import java.io.*; javax.servlet.*; javax.servlet.http.*; java.util.*;

public class SessionDemo extends HttpServlet { public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { HttpSession session = request.getSession(true); response.setContentType("text/html"); PrintWriter out = response.getWriter(); Integer count = new Integer(0); String head; if (session.isNew()) { head = "This is the New Session"; } else { head = "This is the old Session"; Integer oldcount =(Integer)session.getValue("count"); if (oldcount != null) { count = new Integer(oldcount.intValue() + 1); } } session.putValue("count", count); out.println("<HTML><BODY BGCOLOR=\"#FDF5E6\">\n" + "<H2 ALIGN=\"CENTER\">" + head + "</H2>\n" + "<TABLE BORDER=1 ALIGN=CENTER>\n" + "<TR BGCOLOR=\"#FFAD00\">\n" +" <TH>Information Type<TH>Session Count \n" +"<TR>\n" +" <TD>Total Session Accesses\n" + "<TD>" + count + "\n" + "</TABLE>\n" +"</BODY></HTML>" ); }}

6. Write a JSP program that accepts the patient details from user and display the details on the next page. Pat.jsp
<html> <head> <title>Enter the Details </title> </head> <body> <p>&nbsp;</p> <form method="POST" action="disp.jsp"> <h1>Welcome</h1> <p>Enter Pat name:<input type="text" name="fname" size="20"></p> <p>sEnter Pat Id:<input type="text" name="id1" size="20"></p> <p><input type="submit" value="Submit" name="B1"></p> </form> </body> </html>

Disp.jsp
<%@page contentType="text/html" %> <html> <body> <p><%=request.getParameter("fname")%></p>&nbsp; <p><%=request.getParameter("id1")%></p> </body> </html>

You might also like