前台JSP页面代码:
注意type为submit。
servlet中判断代码:
[html] view plaincopy
<form action="http://localhost:8888/LN/SubmitServlet" method=post>
<!--主标题-->
<div class="bigTitle">提交申请</div>
<!--横线-->
<hr class="line"/>
<!--按钮区-->
<div class="btn">
<input name="btnSave" type="submit" value="保存" />
<input name="btnSubmit" type="submit" value="提交" />
<input name="btnClose" type="submit" value="关闭" />
</div> 注意type为submit。
servlet中判断代码:
[java] view plaincopy
public class SubmitServlet extends HttpServlet {
/**
*
*/
private static final long serialVersionUID = 1L;
//PermissiontoApplyBusinessUnit EntityPAB=new PermissiontoApplyBusinessUnit();
public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
String iButton1 = (String)request.getParameter("btnSave");
String iButton2 = (String)request.getParameter("btnSubmit");
String iButton3 = (String)request.getParameter("btnClose");
// request.setAttribute("str", iButton);
//System.out.print(iButton);
if(iButton1 != null){
//request.setAttribute("str1", "1");
System.out.println("保存");
}
else if (iButton2 != null){
//request.setAttribute("str1", "2");
System.out.println("提交");
}
else if (iButton3 != null){
//request.setAttribute("str1", "2");
System.out.println("关闭");
}
request.getRequestDispatcher("/ABUPSubmitApplications.jsp").forward(request, response);
}
public void doPost(HttpServletRequest request,HttpServletResponse response) throws ServletException,IOException{
doGet(request,response);
}
}
本文介绍了一个使用JSP页面进行表单提交并通过Servlet处理请求的示例。重点展示了如何通过不同按钮触发不同的操作,并在Servlet端进行相应的业务逻辑处理。
3929

被折叠的 条评论
为什么被折叠?



