Loading

Servlet-(跳转)表单,超链接,转发,重定向

在制作网页时,我们常用到按钮跳转或者超链接跳转,这时候就用到表单提交或超链接

先说表单,我们可以只有一个提交按钮,也可以在其中添加隐藏表单,就像这样

"<form id=\"form1\" name=\"form1\" method=\"POST\" action=\"Writer3\">" +
                "<input type=\"submit\" value=\"修改\">"+
                "</form>"+

也可以直接简单一点

"<input type=\"button\" value=\"点击返回\" onclick=\"location.href='Writer1'\" />"

超链接的方式

"<br><a href=\"Writer3\" >超链接提交</a>"

转发方式跳转

request.getRequestDispatcher("success.jsp").forward(request, response);    

重定向方式,也就是之前用过的sendRedirect

response.sendRedirect("success.jsp");

也可以这样,直接用url

String site3 = new String("http://localhost:8080/Test01_war_exploded/mess.jsp");
response.setStatus(response.SC_MOVED_TEMPORARILY); response.setHeader(
"Location", site3);
posted @ 2023-03-01 14:54  冰稀饭Aurora  阅读(42)  评论(0编辑  收藏  举报