Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 831629
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T04:14:10+00:00 2026-05-15T04:14:10+00:00

I’ve got a .jsp file that is working fine. It’s maybe a bit special

  • 0

I’ve got a .jsp file that is working fine. It’s maybe a bit special in that it is calling a factory (ArticlesFactory) that returns a singleton (but that is a detail) of class Articles (it does so by automatically fetching shared Google Docs that are transformed to html and then stored into “…/text/en” but that is a detail too).

The following is working fine: it does exactly what I need, it fetches the articles automatically and I can access my Articles instance fine.

<%@ page pageEncoding="UTF-8" contentType="text/html;charset=utf-8" %>
<%@ page import="com.domain.projectname.*"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" dir="ltr" lang="en">
<head></head>
<body>

    <% Articles articles = ArticlesFactory.create( getServletContext().getRealPath( "text/en" )); %>
    We have <%= articles.getNbItems()%>

</body>
</html>

However, I must transform it to some notation I don’t know nor understand, I’m not even sure what the name for that is and obviously I’ve got some issue.

I don’t know if it’s a namespace issue or if there’s a problem with the ArticlesFactory factory’s static factory method creating the Articles singleton:

<?xml version="1.0" encoding="UTF-8"?>
<jsp:root version="2.0" xmlns:jsp="http://java.sun.com/JSP/Page"
    xmlns:c="urn:jsptld:http://java.sun.com/jsp/jstl/core">
<jsp:directive.page import="com.domain.project.ArticlesFactory"/>
<jsp:directive.page contentType="text/html; charset=UTF-8" />

We have ${variable.nbItems}  <!-- What to put here !? -->

</jsp:root>

I tried many things and couldn’t figure it out.

Basically I need to:
– call the static create method from the ArticlesFactory class
– by passing it the result of getServletContext().getRealPath( “text/en” ))

(which should give back an Articles instance)

  • then I want to put the result of getNbItems() in a variable that I want to display

Note that I don’t want to have to call getServletContext from any servlet/dispatcher: I want to do it just like in the first working example (ie directly from inside the .jsp).

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T04:14:10+00:00Added an answer on May 15, 2026 at 4:14 am

    You’re basically looking for “JSP in XML syntax”. Most is already explained in this (old) tutorial. You yet have to replace <% %> by <jsp:scriptlet> and <%= %> by <jsp:expression>.

    The xmlns:c namespace is by the way unnecessary here, unless you’d like to use any of the JSTL core tags.

    The Expression Language (those ${} things) which is explained in this (also old) tutorial is by the way a separate subject. It only acts on objects in the page, request, session or application scope. In scriptlets however, variables are only defined in local scopes (methodlocal actually), those aren’t available in EL. You would need to do the following in the scriptlet to make it available in EL:

    pageContext.setAttribute("articles", articles); // Put in page scope (recommended).
    request.setAttribute("articles", articles); // Or in request scope. Also accessible by any include files.
    session.setAttribute("articles", articles); // Or in session scope. Accessible by all requests in same session.
    application.setAttribute("articles", articles); // Or in application scope. Accessible by all sessions.
    

    This way it’s available by ${articles} in EL.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

No related questions found

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.