Using application scope variables in java

前端 未结 1 807
轻奢々
轻奢々 2020-12-14 03:22

My company is redoing our website over the next few months, going from a ColdFusion website to one written in Java. I am just learning Java and I am curious as to how I can

相关标签:
1条回答
  • 2020-12-14 03:50

    The equivalent is probably the ServletContext

    In your controller servlet:

    ServletContext context = request.getSession().getServletContext();
    

    Just like in the session object you can store attributes in the servlet context as well

    context.setAttribute("someValue", "aValue");
    
    Object attribute = context.getAttribute("someValue");
    

    If you're starting out with Java and you have a non-trivial application to build, I would recommend using a popular framework like Spring or Struts

    0 讨论(0)
提交回复
热议问题