I have requirement like a Java class member variables has to be accessed by 3 or more JSP files. The input to the java class will be a property file. Passing the property file to the constructor will populate the class member variables. This variables will be used by 3 or more JSP files. So instead of creating different instance with same property file, if the instance is once created and if all the JSP can access it, which will be efficient. Currently my idea is making the java class as singleton or other one is create the instance and keep it in a session and let all the jsp to access it. I feel singleton class is more appropriate. Is my decision rite or any other more efficient way is there ?

我有类似Java类成员变量的要求必须由3个或更多JSP文件访问。 java类的输入将是属性文件。将属性文件传递给构造函数将填充类成员变量。这些变量将由3个或更多JSP文件使用。因此,不是使用相同的属性文件创建不同的实例,如果实例是一次创建的,并且所有JSP都可以访问它,这将是有效的。目前我的想法是将java类作为单例或其他人创建实例并将其保存在会话中并让所有jsp访问它。我觉得单身课更合适。是我的决定仪式还是其他任何更有效的方式?

1 个解决方案

#1


0

I would only advice to keep objects in session which are session dependent. In this case, since you have to make the variable accessible in 3 different jsp's and these values are not dependant on individual request, better to store the object in application context.

我只建议将会话中的对象保持为会话依赖。在这种情况下,由于您必须在3个不同的jsp中访问变量,并且这些值不依赖于单个请求,因此最好将对象存储在应用程序上下文中。

Use ServletContext's getAttribute() and setAttribute() methods.Store the values in Application Scope and you should be done for good.

使用ServletContext的getAttribute()和setAttribute()方法。存储Application Scope中的值,你应该做得很好。

更多相关文章

  1. [java混淆器问题] 如何让web项目的class文件不能被反编译,又能在w
  2. Java: SAX解析一个巨大的XML文件。
  3. 使用Java语言如何实现快速文件复制?
  4. Javascript实现页面加载完成后自动刷新一遍清除缓存文件
  5. 为可执行文件夹提供自定义图像
  6. java写入文件的几种方法小结
  7. 使用SAX Filter将新元素插入XML文件
  8. 在文件中添加新数据后,JComboBox不会刷新
  9. 小聊天程序,访问文件之间的变量

随机推荐

  1. 开发板挂载vmware虚拟机linux下nfs服务器
  2. Linux下符号版本原理及实现
  3. 工作中常用的Linux命令
  4. linux从0开始----01
  5. Linux2.6内核下键盘输入设备驱动的实现
  6. 一键安装linux (附带各种命令,登录欢迎界
  7. Linux之I2C设备总结
  8. CUDA统一内存工作(具体来说,cudaMallocMana
  9. 在recvfrom系统调用期间取消C ++ 11 std
  10. Android实现FM收音机