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 8708263
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T04:05:16+00:00 2026-06-13T04:05:16+00:00

I am trying to print value of a function variable in JSP Page. The

  • 0

I am trying to print value of a function variable in JSP Page. The function variable is located in java.class(com.project.bulk). File name is bulk.class. I tried reading the variable by writing below code in JSP file and it didn’t work. Any help please?

<%@ page import="com.project.bulk.bulk" %>

<%=bulk.cellStoreVector %>

// function code is below

private static void printCellDataToConsole(Vector dataHolder) {

            for (int i = 0; i < dataHolder.size(); i++) {
                    Vector  cellStoreVector  = (Vector) dataHolder.elementAt(i);
                    System.out.println(cellStoreVector);
                    for (int j = 0; j < cellStoreVector.size(); j++) {
                          HSSFCell myCell = (HSSFCell) cellStoreVector.elementAt(j);
                          String stringCellValue = myCell.toString();
                         // System.out.print(stringCellValue + "\t\t");
                    }
                    System.out.println();
            }
    }
  • 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-06-13T04:05:17+00:00Added an answer on June 13, 2026 at 4:05 am

    You can’t access a local variable outside that method or the block in which it is defined. The scope of local variable is confined in the block where it is defined.

    Your below declaration is local to the for-loop in which it is declared. Even in the current method, it will not be accessible outside the for-loop. Because your loop defined a scope of access for this variable: –

    Vector  cellStoreVector  = (Vector) dataHolder.elementAt(i);
    

    To access it in a JSP outside your class, declare that field as a private instance variable in your class. And have a public accessor method, that will return the value of that field. Then in your JSP, you can invoke that method to get the value for a particular instance.

    Remember, you need to access that method on an instance of your class. You are accessing here directly through your class name. If you want to access it like that, you need a static variable.

    Here’s a simple example covering what all I said above: –

    public class Dog {
    
        // Private Instance variable
        private int instanceVar; // Defaulted to 0
    
        // Private Static variable
        // Common for all instances
        private static String name = "rohit";
    
    
        // Public accessor
        public int getInstanceVar() {
            return this.instanceVar;
        }
    
        public void setInstanceVar(int instanceVar) {
            this.instanceVar = instanceVar;
        }
    
        // Static public accessor for static variable
        public static String getName() {
            return name;
        }
    
    }
    
    class Test {
        public static void main(String[] args) {
            // Access static method through class name
            System.out.println(Dog.getName()); 
    
            Dog dog = new Dog();
    
            // Set instance variable through public accessor, on a particular instance
            dog.setInstanceVar(10);
    
            // Get instance variable value and asssign to local variable x
            // x is local variable in `main`
            int x = dog.getInstanceVar(); 
    
            showX(); 
        }
    
        public static void showX() {
    
            // x not visible here.
            System.out.println(x);  // Will not compile
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to print a variable value within the javascript function. If the
Im trying print Excel file data on a page. To do it i used
I am trying to pass a variable from a function to a class. Example
I'm trying to search mongo collection to retrieve some value based on variable name,
I'm trying to pull the value of a variable from inside a function in
I need to pass a variable from Admin.java file to index.jsp. I get the
I'm trying to print out a list of products on a page. This is
I am trying to store a value in a module level variable for later
I am trying to reference to a class variable which is a vector and
I have a register.jsp file. It reads the variable from a form submitted as

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.