一般很少用按钮调用servlet,但还是可以的。
eg:
/************************************Login.jsp******************************/
<script type="text/javascript">
function test(name) {
location.href = Servlet+'?name='+name;
}
</script>
<input type="button" value="调用" />
这样虽然可以直接调用,但是也不提倡这种方法,可以这样————————
/************************************Login.jsp******************************/
<script type="text/javascript">
function test(name) {
location.href = "doLogin.jsp";
}
</script>
<input type="button" value="调用" />
/*****************************************doLogin.jsp****************************/
<%
response.sendRedirect("Servlet");
%>
本文介绍了通过按钮直接调用Servlet的技术实现方式,并探讨了这种做法的利弊。虽然这种方式可行,但由于它绕过了传统的表单提交过程,可能会导致一些问题,因此不建议常用。文章还提供了一种替代方案,即通过中间页面进行跳转。

255

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



