有没有办法直接从 JSP 页面中的按钮调用 servlet?然而,这不是 POST 表单提交按钮。它只是一个按钮,应该调用doGet()
方法来获取一些值并转发到另一个 JSP。
这是小服务程序:
public class PopulateProjectServlet extends HttpServlet {
private static final long serialVersionUID = 1L;
public PopulateProjectServlet() {
super();
}
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
try {
List<Project> projects = PopulateProject.getProjects();
request.setAttribute("projects", projects);
request.getRequestDispatcher("/UserHome/Projects.jsp").forward(request, response);
}
这是带有按钮的 JSP 页面:
</head>
<body>
<input type="button" value="Update" onclick="<%MyServletName.Update(request, response);%>"></input> **<--- I FOUND SOMETHING LIKE THAT BUT DIDNT WORK**
<a href="/EmployeeLeaveForm/UserHome/Projects.jsp"> <button type=submit action="com.eteration.leavesystem.service.PopulateProjectServlet">Projeler</button></a>
<a href="/EmployeeLeaveForm/SharedByAll/Leave.jsp"> <button type=submit>Izin al</button></a>
<a href="/EmployeeLeaveForm/SharedByAll/LeaveCancelUpdate.jsp"> <button type=submit>Guncelle/Iptal et</button></a>
<a href="/EmployeeLeaveForm/SharedByAll/History.jsp"> <button type=submit>Gecmis</button></a>
<a href="/nextpage.jsp"> <button type=submit>cikis</button></a>
</body>
</html>
如何使按钮首先到达 servlet,然后再转发到 JSP 页面?