Normal
0
7.8 磅
0
2
false
false
false
EN-US
ZH-CN
X-NONE
MicrosoftInternetExplorer4
/* Style Definitions */
table.MsoNormalTable
{mso-style-name:普通表格;
mso-tstyle-rowband-size:0;
mso-tstyle-colband-size:0;
mso-style-noshow:yes;
mso-style-priority:99;
mso-style-qformat:yes;
mso-style-parent:"";
mso-padding-alt:0cm 5.4pt 0cm 5.4pt;
mso-para-margin:0cm;
mso-para-margin-bottom:.0001pt;
mso-pagination:widow-orphan;
font-size:10.0pt;
font-family:"Times New Roman","serif";}
在转发情况下,共享request域对象,会将参数从第一个业务控制方法传入第二个业务控制方法,
反之,重定向则不行
删除id=10号的用户,再查询用户。
给出具体的实现代码:
@Controller @RequestMapping(value="/user") public class UserAction { @RequestMapping(value="/delete") public String delete(int id) throws Exception{ System.out.println("删除用户->" + id); //转发到find() return "forward:/user/find.action"; //重定向到find() //return "redirect:/user/find.action"; } @RequestMapping(value="/find") public String find(int id) throws Exception{ System.out.println("查询用户->" + id); return "/success.jsp"; } }
上面的例子中如果是转发的话这个id可以从delete传到find中,但是用重定向就不能,那我就想用重定向怎么办?怎么把id传过去,一种解决办法,把id的值保存在Seeion中(不推荐,因为这样就引入HttpServletrequest)那就采用第二种方式:代码如下:
采用了:return "redirect:/emp/update.action?id="+id 这种形式。
Normal
0
7.8 磅
0
2
false
false
false
EN-US
ZH-CN
X-NONE
MicrosoftInternetExplorer4
/* Style Definitions */
table.MsoNormalTable
{mso-style-name:普通表格;
mso-tstyle-rowband-size:0;
mso-tstyle-colband-size:0;
mso-style-noshow:yes;
mso-style-priority:99;
mso-style-qformat:yes;
mso-style-parent:"";
mso-padding-alt:0cm 5.4pt 0cm 5.4pt;
mso-para-margin:0cm;
mso-para-margin-bottom:.0001pt;
mso-pagination:widow-orphan;
font-size:10.0pt;
font-family:"Times New Roman","serif";}