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

  • Home
  • SEARCH
  • 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 6910267
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T08:47:33+00:00 2026-05-27T08:47:33+00:00

lets say I have a class like this: public class MyClass { private String

  • 0

lets say I have a class like this:

public class MyClass {

    private String name;

    public MyClass(final String name) {
        this.name = name;
    }

    public static void startMe() {
        //do something
    }

    public static String gimmeString() {
        //do something
        return "myString";
    }

    public MyClass getObject(final String name) {
        //do something
        return new MyClass(name);
    }
}

At first I would like to know how to start the function “startMe” in the class MyClass with JSTL? Nothing more, just start this function. Then how to start AND display the string in the function “gimmeString”. At last (yeah it looks funny) I would like to get access to the function getObject(name) AND save this in a JSTL variable (or something so I can use this object later).

I just know that I need Beans. And after that no idea how to use it with JSTL, I have something like that:

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<jsp:useBean id="start" scope="session" class="com.MyClass"/>
<%-- and now? <c:?? --%>
</body>
</html>

Thank you

  • 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-27T08:47:34+00:00Added an answer on May 27, 2026 at 8:47 am

    You can’t do that cleanly without using a preprocessing servlet or a MVC framework like JSF. The <jsp:useBean> only offers facilities to get/set model values. Nothing more. It can absolutely not supplant the Controller part of MVC.

    You could workaround this by introducing lazy loading in a getter or lazy executing in a setter.

    E.g. lazy loading:

    public String getString() {
        if (string == null) {
            start();
        }
    
        return string;
    }
    

    with

    ${start.string}
    

    or, lazy executing:

    public void setString(String string) {
        if (this.string == null) {
            start();
        }
    
        this.string = string;
    }
    

    with

    <jsp:setProperty name="start" property="string" value="somevalue" />
    

    Keep in mind that is an ugly hack. You should really look into servlets or MVC frameworks. If you’re still new to the stuff, start with a simple servlet. See also our servlets wiki page for some hello world examples. Note that when you’re using servlets, you do not need <jsp:useBean> and consorts anymore.

    Your concrete functional requirement is actually unclear. Particularly having a public static method in a session scoped bean is confusing. If you actually want to call a method on webapp’s startup, use ServletContextInitializer#contextInitialized(). Or if you want to call a method on creation of a session, use HttpSessionListener#sessionCreated().

    Oh, your bean’s design is incorrect. It should have a (implicit) no-arg default constructor.

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

Sidebar

Related Questions

Lets say I have a class like this in class1.vb: Public Class my_class Public
Lets say I have a class like this in Java: public class Function {
lets say I have the following public class A { private string _someField; public
Lets say i have the following scenario: public class A { public String createString(final
Lets say I have a two classes like this: public class LocalResources { public
Lets say I have a class like this: public class Foo { public Foo
Lets say I have a controller class like this. public class InStorePickupController : Controller
Lets say I have a set of model classes like this: public class Person
Let's say I have a Java class like this: public class MyClass { public
Lets say i have a class like this class book { public $title; public

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.