I have a JSP which has a form with a submit button (with value "Start Server"). When I click on this button it calls a method (java code) and starts up a server. Now the button value is changed to "Stop Server" based on a boolean method "getServerStatus()"
My jsp is as follows
<form class="form" id="hubForm" method="post" action="/ServManager/servmgr">
<c:if test="${requestScope.servStatus == 'true'}">
<input type="submit" name="action" id="stopServer" value="Stop Server" />
</c:if>
<c:if test="${requestScope.servStatus != 'true'}">
<input type="submit" name="action" id="startServer" value="Start Server" />
</c:if>
</form>
My servlet is as follows
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
request.getRequestDispatcher("/servmanager.jsp").forward(request, response);
}
@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
ServManager servmgr = new ServManager();
String action = request.getParameter("action");
if(action.equalsIgnoreCase("start server")) {
servmgr.startServer();
}
else {
servmgr.stopServer();
}
boolean servStatus = servmgr.getServerStatus();
request.setAttribute("servStatus", servStatus);
request.getRequestDispatcher("/servmanager.jsp").forward(request, response);
}
getServerStatus() is as follows
public boolean getServerStatus()
{
return blStatus;
}
My questions is
- When I start the webpage it always has the button displayed as "Start Server" even though the server is running. How do I check the status of the server using getServerStatus() method and display "Stop Server" button when the page is loaded and if the server is already running when the page is loaded
- Did I do the other stuff right in this page?
Pls help. Thanks and Happy new year!