我目前正在尝试使用Activiti完成一个简单的Web项目。我是在Eclipse中使用Tomcat 7.0服务器完成的。我有一个应该显示任务信息的servlet,但即使有问题,它肯定还应该显示一些东西。
我只是开始学习JSP所以我为我在代码中犯下的任何愚蠢错误道歉。
的index.html:
<!DOCTYPE html>
<html>
<head>
<meta charset="ISO-8859-1">
<title>Main Page</title>
</head>
<body>
<h1>Welcome.</h1>
<br />
<h3>Go to:</h3>
<ul>
<li><a href="loanrequest.jsp">Request Loan</a></li>
<li><a href="ManagementTasks">Management Tasks</a></li>
</ul>
</body>
</html>
我的servlet:
import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.activiti.engine.ProcessEngine;
import org.activiti.engine.ProcessEngines;
import org.activiti.engine.TaskService;
import org.activiti.engine.task.Task;
/**
* Servlet implementation class ManagementTasks
*/
@WebServlet("/ManagementTasks")
public class ManagementTasks extends HttpServlet {
private static final long serialVersionUID = 1L;
/**
* @see HttpServlet#HttpServlet()
*/
public ManagementTasks() {
super();
// TODO Auto-generated constructor stub
}
/**
* @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
*/
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
response.setContentType("text/html");
PrintWriter out = response.getWriter();
out.println("<html><head><title>Management Tasks</title</head><body>");
ProcessEngine processEngine = ProcessEngines.getDefaultProcessEngine();
TaskService taskService = processEngine.getTaskService();
List<Task> tasks = taskService.createTaskQuery()
.taskCandidateGroup("management").list();
if (tasks.size() > 0) {
out.println("<h1>You have " + tasks.size() + " task(s) to complete.</h1>");
Task t = tasks.get(0);
out.println("<br /><br /><h2>" + t.getDescription() + "</h2>");
out.println("<br />Do you want to approve this request?</h2><br />");
out.println("<form method=\"POST\" action=\"ManagementApproval\">");
out.println("<label for=\"approve\">Do you approve?</label>");
out.println("<select name=\"approve\">");
out.println("<option value=\"true\">Yes</option>");
out.println("<option value=\"false\">No</option>");
out.println("</select><br />");
out.println("<input type=\"hidden\" id=\"taskId\" name=\"taskId\" " + "value=\"" + t.getId() + "\" /><br/>");
out.println("<input type=\"submit\" value=\"Submit Form\" />");
out.println("<input type=\"reset\" value=\"Reset Form\" />");
out.println("</form>");
} else {
out.println("<h1>There are no tasks for you. </h1>");
}
out.println("<a href=\"index.html\"> HOME </a>");
out.println("</body></html>");
out.close();
}
/**
* @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
*/
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
}
}