服务器1:
public void test1() throws IOException{
ActionContext ctx = ActionContext.getContext();
HttpServletRequest request = (HttpServletRequest)ctx.get(ServletActionContext.HTTP_REQUEST);
HttpServletResponse response = (HttpServletResponse)ctx.get(ServletActionContext.HTTP_RESPONSE);
ctx.getSession().put("str", "1234567890+++++++实验成功了");
String port= request.getLocalPort()+"";
System.out.println("端口号为:"+port);
response.sendRedirect("http://localhost:8080/项目1 /命名空间1/test1.action");
}
public String test2() throws IOException{
ActionContext ctx = ActionContext.getContext();
HttpServletRequest request = (HttpServletRequest)ctx.get(ServletActionContext.HTTP_REQUEST);
HttpServletResponse response = (HttpServletResponse)ctx.get(ServletActionContext.HTTP_RESPONSE);
ctx.getSession().put("str", "1234567890+++++++实验成功了???????覆盖掉就对了");
return "success";
}
服务器2
public void test1() throws IOException{
ActionContext ctx = ActionContext.getContext();
HttpServletRequest request = (HttpServletRequest)ctx.get(ServletActionContext.HTTP_REQUEST);
HttpServletResponse response = (HttpServletResponse)ctx.get(ServletActionContext.HTTP_RESPONSE);
response.sendRedirect("http://localhost:8080/项目2 /命名空间2/test2.action");
}
页面
...
<%@ taglib uri="/struts-tags" prefix="s" %>
...
${str}<br>
本文详细介绍了服务器端操作,包括设置会话属性、获取本地端口号,并通过重定向实现页面跳转。同时展示了如何在页面上显示会话中存储的字符串。
21万+

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



