java怎么多次调用一个servlet,转向不同页面?求具体代码。
1个回答
展开全部
实现方法:
1、jsp写法如下:
<form id="myForm" action="TheServlet" method="POST">
<input type="hidden" name="action" id="action" />
<input type="submit" value="Register User" onclick="setAction('registerUser');" />
<input type="submit" value="Create Ad" onclick="setAction('createAd');" />
</form>
<script type="text/javascript">
function setAction(var action) {
document.getElementById('action').value = action;
}
</script>
2、servlet写法如下:
@WebServlet("TheServlet")
public class TheServlet extends HttpServlet {
@Override
public void doPost (HttpServletRequest request, HttpServletResponse response)
throws IOException {
String action = request.getParameter("action");
if (action.equals(...)) {//多分支跳转
} else if (action.equals(...)) {
} else ...
//if using Java 7 or later, you could use a switch instead of ifs
}
}
1、jsp写法如下:
<form id="myForm" action="TheServlet" method="POST">
<input type="hidden" name="action" id="action" />
<input type="submit" value="Register User" onclick="setAction('registerUser');" />
<input type="submit" value="Create Ad" onclick="setAction('createAd');" />
</form>
<script type="text/javascript">
function setAction(var action) {
document.getElementById('action').value = action;
}
</script>
2、servlet写法如下:
@WebServlet("TheServlet")
public class TheServlet extends HttpServlet {
@Override
public void doPost (HttpServletRequest request, HttpServletResponse response)
throws IOException {
String action = request.getParameter("action");
if (action.equals(...)) {//多分支跳转
} else if (action.equals(...)) {
} else ...
//if using Java 7 or later, you could use a switch instead of ifs
}
}
本回答被提问者和网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询