我有一个JSP,它有一个带有提交按钮的表单(值为#34; Start Server")。当我点击这个按钮时,它会调用一个方法(java代码)并启动一个服务器。现在按钮值更改为"停止服务器"基于布尔方法" getServerStatus()"
我的jsp如下
<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>
我的servlet如下
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()如下
public boolean getServerStatus()
{
return blStatus;
}
我的问题是
请帮助。谢谢,新年快乐!