Improvement of this method I'm coding a small web app with no real functionality. It's like a pilot program for something bigger. What I want is construct a program that works as a clock on/off for a restaurant. Actually I'm just trying to simulate one. What I'v done is working but I would like to know whether there is any java class that I can use in a session to calculate the difference between the clock on and off.

Index.jsp

&lt;%@page import="javax.media.jai.operator.EncodeDescriptor"%&gt;
&lt;%@page contentType="text/html" pageEncoding="UTF-8"%&gt;
&lt;!DOCTYPE html&gt;
&lt;html&gt;
    &lt;head&gt;
        &lt;meta http-equiv="Content-Type" content="text/html; charset=UTF-8"&gt;
        &lt;title&gt;Project&lt;/title&gt;
    &lt;/head&gt;
    &lt;body&gt;
        &lt;h1&gt;Employees&lt;/h1&gt;
        &lt;form action=&lt;%= response.encodeURL("CheckUser") %&gt; method="get"&gt;
            &lt;input type="hidden" name="userId" value="1"&gt;
            &lt;input type="submit" value="Diogo"&gt;

        &lt;/form&gt;
    &lt;/body&gt;
&lt;/html&gt;


CheckUser

public class CheckUser extends HttpServlet {


    protected void processRequest(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {

        String userId = request.getParameter("userId");
        User user1 = new User();
        user1.setUserId(userId);

        HttpSession session = request.getSession();
        session.setAttribute("userId", userId);

        Hours h1 = (Hours) session.getAttribute("hours");

        if (h1 == null){
        h1 = new Hours(user1);
        }


        Calendar cal = new GregorianCalendar();


        h1.setMinutes(cal.get(Calendar.MINUTE));

        request.setAttribute("hours", h1);
        String url = "/show.jsp";

        session.setAttribute("hours", h1);




        RequestDispatcher dispatcher = getServletContext().getRequestDispatcher(url);
        dispatcher.forward(request, response);

    } 


show.jsp

&lt;!DOCTYPE html&gt;
&lt;html&gt;
    &lt;head&gt;
        &lt;meta http-equiv="Content-Type" content="text/html; charset=UTF-8"&gt;
        &lt;title&gt;JSP Page&lt;/title&gt;
    &lt;/head&gt;
    &lt;body&gt;
        &lt;%@ page import="Business.*, process.*" %&gt;

        &lt;%
            String userId = (String) session.getAttribute("userId");
            Hours h = (Hours) session.getAttribute("hours");
            String actualMinute = h.getMinutes();
            String calcMinute = h.getCalMinutes();
        %&gt;
        &lt;h1&gt;&lt;%= userId %&gt;&lt;/h1&gt;
        &lt;h1&gt;&lt;%= h.getMinutes() %&gt; minuto atual&lt;/h1&gt;

        &lt;% 
        if(!actualMinute.equalsIgnoreCase(calcMinute) || calcMinute == "0")
           { 
        %&gt;

        &lt;h1&gt;&lt;%= h.getCalMinutes() %&gt; minutes&lt;/h1&gt;
        &lt;%
        }else
           {
        %&gt;        
            &lt;h1&gt;It is working&lt;/h1&gt;
            &lt;h1&gt;&lt;%= h.getCalMinutes() %&gt;&lt;/h1&gt;
        &lt;%
           }
        %&gt;    


        &lt;form action="&lt;%= response.encodeURL("index.jsp") %&gt;" method="get"&gt;
            &lt;input type="submit" value="return"&gt;
        &lt;/form&gt;
    &lt;/body&gt;
&lt;/html&gt;
I assume that Hours is a custom class of yours.  


If you are asking if there is an existing Java class that will automagically calculate the "difference" between two instances of your custom class, the the answer is "No".
If you are asking (more generally) what is the best class for handling temporal quantities so that you can compare them, calculate differences and so on, then the answer is to look at the JodaTime libraries.




I also note that you are STILL using "Business" as a package name.  You should stop it before The Protectors of Java Purity find a way to hack your PC and fill the disc drive with zeros!!!

Seriously, it is bad practice.  Don't do it.  Follow the standard Java naming conventions, like professional developers do.