JSP Interview Questions and Answers

    1 Votes

33. What is the use of [ ] operator in JSP Expression Language (EL)?

The [ ] operator can be used instead of the period operator.
  • To access be ${person[“name”]} reads the property named name in the person bean. Equivalent to ${person.name}.
  • To access map values: ${country[“ind”]} retrieves the value for the key ind in the country map. Equivalent to ${country.ind}.
  • To access elements from arrays and list: ${fruits[1]} retrieves the value at index 1 in the fruits array (list}.
34. How to read request parameter values using JSP Expression Language (EL)?
Request parameter values can be read as shown:
${param.userName} or ${param[“userName”]}
Reads the value of the parameter named userName set in the request. If a single request parameter name contains an array of values, example in the case of checkbox parameter. We use,
${paramValues.hobbies[0]}

Reads the first value of the check box hobbies.

35. How to read attributes in JSP Expression Language?

Take a scenario in which you need to access an attribute with name Username stored in some scope we use ${Username} searches the PageContext, HTTPServletRequest, HTTPSesson and ServletContext(in that order) for an attribute named Username. Suppose if we want to get the attribute with name ‘name’ in a specific scope say session, we use {sessionScope.name}.

36. How to access collection objects in JSP Expression Language?

Consider attributeName is a scoped variable referring to an array, List or Map, an entry in the collection can be accessed by ${attributeName[entryName]}.

37. How to deactivate expression language evaluation in JSP?

If your application requires EL to be ignored it can be done by setting the is EL ignored attribute to true in the page directive.

<%@ page isELIgnored=”true” %>

38. When to use JSP Expression Language?

EL should be used for accessing and presenting data from implicit objects. Don’t use EL operators and conditions for performing business logic which should be strictly done in business components.

39. What is server side java bean?

It is a class used to store the details of real world entities. For Example,

  • Employee --> Employee Name and Employee Salary
  • Student --> Student Name and Student Address

Bean is a plain java class which contains

  • Fields or properties: Fields to store the data, example: Employee name, salary.
  • Methods: Methods for retrieving and modifying the attributes like setEmployeeName(), setStudentAddress. These methods are referred to as accessors/mutator.

40. What is the design conventions for Java Bean?

A Java Bean component property can be read/write, read-only, or write-only. The bean property needs to be accessible using public methods. For each readable property, the bean must have a method to retrieve the property value.

public Datatype get<PropertyName>
{
return value; //Returns the property value
}

For each writable property, the bean must have a method.

public void set<PropertyName>(Datatype newValue)
{
Property=newValue; //sets the new value into the property
}

41. Why to follow naming conventions for java bean methods?

The web container maps the request attribute with the method names and triggers the appropriate methods for retrieving or setting the values. For Example,

Request Attribute Name: empId

Method Triggered: setEmpId(), getEmpId()

Web container automatically capitalizes the first character of the attribute name and concatenates “set” or “get” to it for either setting or retrieving property values in bean.

42. How web container finds the properties and invokes the methods of java bean from JSP page?

Web container uses the reflection and introspection java api’s for finding the properties and methods of a class and invoking it dynamically.

43. What is the need of beans in JSP?

Need of beans in JSP are:

  • Beans are used to JSP for collectively storing some information.
  • Beans makes transfer of data between JSP’s easier.

For example, if you are handling with a registration form all the registration details can be loaded into a RegistrationBean and can be transported across other components as a single object.

44. What is JSP action tag?

JSP action tags are a set of predefined tags provided by the JSP container to perform some common tasks thus reducing the java code in JSP.

45. Mention some of the common tasks of JSP?

Some of the common tasks are:

  • Instantiate java bean object.
  • Setting values to beans.
  • Reading values from beans.
  • Forward the request to another resource.
  • Including another resource.

46. What is the syntax for JSP action tag?

Syntax for JSP action tag is given below:

<jsp:action_name attribute=”value”/>

Where, Action_name : specifies the name of the action to be performed. Attribute : specifies the attributes relevant to the action.

For Example,

<jsp:include page=”myPage.jsp”/>

Where “include” is the action and “page” is the attribute of the action include.

47. Mention action tags available in JSP?

The following are the action tags available in JSP:

  • jsp:include
  • jsp:forward
  • jsp:usebean
  • jsp:setProperty
  • jsp:getProperty
  • jsp:param
  • jsp:fallback
  • jsp:element
  • jsp:body
  • jsp:text
  • jsp:attribute
  • jsp:plugin

48. what is the use of jsp:include action tag?

It is used for dynamically including the pages. It includes the output of the included page during runtime. Contents of the page are not included, only the response is included. Assume that the following line is included in index.jsp

<jsp:include page=”myPage.jsp” />

Here the response of myPage.jsp is included in the index.jsp.

Page 3 of 5

Popular Videos

communication

How to improve your Interview, Salary Negotiation, Communication & Presentation Skills.

Got a tip or Question?
Let us know

Related Articles

Servlet Interview Questions and Answers
Advanced Servlet Interview Questions and Answers
EJB Interview Questions and Answers
Spring Interview Questions and Answers