0% found this document useful (0 votes)
11 views

Practice Set 2

Uploaded by

Ashu Singh
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
11 views

Practice Set 2

Uploaded by

Ashu Singh
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

Practice Set

What is meaning of Synchronous request and Asynchronous request? Mention the working of AJAX

Write the ways using that we can deploy an application. Write the steps.

How can we use pseudo-classes and pseudo-elements in CSS? Provide examples.

What is the meaning of HTTP Status Code. Explain codes 200, 500,400, 403 & 404.

Explain jQuery with a suitable example.

What is JDBC? Write the steps to fetch data from a database.

What is the purpose of <Java Server Pages (JSP):setProperty >?

What is a bean ? use setter and setter method in a bean program.

With the help of Java script code block which checks the contents entered in a text box of a form. If
the test entered is in the lower case, convert to upper case using the builtin function.

Explain the use of JSP/ Servlet in web application. Write down the directory structure of the
application using a servlet.

How can we handle the exceptions in Java Server Pages (JSP)? Explain with a suitable example.

How is HTML 4.0 different from HTML 5.0.

Why do we use action tags in JSP? Explain with a suitable example.

What is the use of JDBC drivers? Explain different types of JDBC drivers.

How can we create a dedicated error page in Java Server Pages (JSP)?

What are the different types of Javascript errors?

Compare iteration and recursion using Javascript.

Why do we use client side scripting? Also explain the importance of server side scripting.

Write a Servlet which includes the content of another Servlet (ie data of other servlet is coming to
your servlet).

Write a Servlet which forwards request to another servlet

Write a Servlet which receives initialization values from web.xml

web.xml
<web-app>
<servlet>
<servlet-name>Config</servlet-name>
<servlet-class>ConfigDemo</servlet-class>
<init-param>
<param-name>username</param-name>
<param-value>studyglance</param-value>
</init-param>
</servlet>
<servlet-mapping>
<servlet-name>Config</servlet-name>
<url-pattern>/welcome</url-pattern>
</servlet-mapping>
</web-app>

ConfigDemo.java
// Import required java libraries
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;

// Extend HttpServlet class


public class ConfigDemo extends HttpServlet {

public void doPost(HttpServletRequest request, HttpServletResponse response)


throws ServletException, IOException {

// Set response content type


response.setContentType("text/html");

// Actual logic goes here.


PrintWriter out = response.getWriter();

//get ServletConfig object.


ServletConfig config=getInitServletConfig();

//get init parameter from ServletConfig object.


String name= config.getParameter("username");
out.println("Welcome "+name);
out.close()
}
}

ServletContext
ServletContext object can be used to get configuration information from web.xml file. There is only
one ServletContext object per web application. If any information is shared to many servlet, it is
better to provide it from the web.xml file using the element.

Methods commonly used in ServletContext interface


public String getInitParameter(String name):Returns the parameter value for the specified
parameter name.
public Enumeration getInitParameterNames():Returns the names of the context's initialization
parameters.
public void setAttribute(String name,Object object):sets the given object in the application scope.
public Object getAttribute(String name):Returns the attribute for the specified name.
web.xml
<web-app>
<context-param>
<param-name>driver</param-name>
<param-value>com.mysql.jdbc.Driver</param-value>
</context-param>
<servlet>
<servlet-name>Context</servlet-name>
<servlet-class>ContextDemo</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>Context</servlet-name>
<url-pattern>/welcome</url-pattern>
</servlet-mapping>
</web-app>

ConfigDemo.java
// Import required java libraries
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;

// Extend HttpServlet class


public class ContextDemo extends HttpServlet {

public void doPost(HttpServletRequest request, HttpServletResponse response)


throws ServletException, IOException {

response.setContentType("text/html"); // Set response content type

PrintWriter out = response.getWriter();

ServletContext context=getServletContext(); //get ServletContext object.


String driverName= context.getInitParameter("driver"); //get init parameter from ServletConfig object.
out.println("driver name is = "+driverName);
out.close()
}
}
,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
Construct an HTML code using various text formatting tags

List some features of jQuery.

Discover the benefits of using JavaScript

Outline the various http methods used to send an html form’s data to server in details.Explain with
the help of a program.

What is the utility of Spring boot in web programming? Explain its working
Write an Servlet / Java Server Pages (JSP) program to calculate Perimeter and area using post & get
method

Write a Servlet code snippet using PreparedStatement to insert data into a table in a MySQL/ Oracle
database.

What is the use of Spring and Spring Boot in web application. Explain with a suitable example

Write a Servlet/ Java Server Pages (JSP) program to validate user login. User data is available in
database

Write a Servlet/ Java Server Pages (JSP) program to maintain session using session object, Hidden
Form Field and URL Rewriting

Explain the use of SPAN in HTML with an example?

What is the utility of Spring in web programming? Explain

Create a table inside a table

Create an HTML form in which accept marks of 5 subjects and submit marks to a servlet. Calculate
the division of the students based upon following criterion

Marks >= 60 First Division


Marks <60 && >= 45 Second Division
Marks <45 && > 33 Third Division
Marks < 33 Fail

State with an example the various way to add JavaScript and CSS to HTML.

Write a Servlet/ Java Server Pages (JSP) program showing Page Navigation using Send redirect &
RequestDispatcher

Develop an application using AJAX and Java Server Pages (JSP) that contains html page that accept
email and check and display a message email is present in the database or not. Create an user and
store data in database

How do we use custom tag in Java Server Pages (JSP)? Formulate steps to create a custom tag.

Elaborate Document Object Model (DOM) with different JavaScript objects. Write a program to
show system information and navigation information

What is the meaning of implicit objects of Java Server Pages (JSP). Show the uses with a suitable
program.

Write a JSP/Servlet program to generate the exponential of a user entered value.


Write a Java Server Pages (JSP) program to maintain session using session object.

Write a JSP/Servlet program using preparedStatement in entering data in MySQL/ Oracle table. Also
display the result

Assume four users user1, user2, user3 and user4 having the passwords pwd1, pwd2, pwd3 and pwd4
respectively. Write a servlet/ JSP for doing the following. Create a Cookie and add these four user
id’s and passwords to this Cookie. 2. Read the user id and passwords entered in the Login form and
authenticate with the values available in the cookies.

Design a table with the following fields: name, password, email-id, and phone number.
Write a program using Servlets or JavaServer Pages (JSP) to connect to the database, retrieve
data from the table, and display it. Additionally, implement functionality to insert user details
into the table when a new user registers by clicking the submit button on the registration
page.

Create a webpage that includes various form elements such as Text area, select, text box,
checkboxes, and radio buttons. Implement functionality using JavaScript to display the data entered
by the user.

Design a shopping cart for an apparel store with session tracking API.

Write a program of Servlet/ JSP in which pass three input using form element and find the greatest
on in main.jsp page. If the greatest number is even then send control to Even.jsp otherwise odd.jsp

Write a program of Servlet/ JSP in which pass three input using form element Name, Age and Marks.
Use cookie / session objects to maintain session and send data to third page and print all.

Explain MVC architecture in web application. Explain with a suitable example.

Difference between ServletConfig vs. ServletContext


ServletConfig ServletContext

ServletConfig object is ServletContext object is global to the entire web


one per servlet class. application.

Object of ServletConfig Object of ServletContext will be created at the time


will be created during of web application deployment
the initialization process
of the servlet.

We have to give the ServletContext object can be available even before


request explicitly in giving the first request.
order to create the
ServletConfig object for
the first time.

Scope: As long as a Scope: As long as a web application is executing,


servlet is executing, the the ServletContext object will be available, and it
ServletConfig object will be destroyed once the application is removed
will be available, it will from the server.
be destroyed once the
servlet execution is
completed.

ServletConfig object is ServletContext object is used while application


used while only one requires information shared by it.
servlet requires
information shared by
it.

getServletConfig() getServletContext() method is used to obtain


method is used to obtain ServletContext object.
Servletconfig object.

In web.xml — tag will In web.xml — tag will be appear under tag.


be appear under tag.

You might also like