spring实现页面跳转功能 当用户需要执行某个操作,该操作需要用户登录之后才能操作,该用户尚未登录,跳转到登录 登录后跳转到原页面。求示例。 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 使用refer,在跳转到登陆之前,传递当前界面地址,登陆之后,再直接跳转到刚才传递的地址参数即可。 http://www.360doc.com/content/10/0422/11/15643_24320208.shtml <result name="success">/其他页面</result>////成功跳转<result name="error">/login</result>/////原来的页面在你的action里面返回值 如果返回 SUCCESS 就跳转到了其他页面如果返回了 ERROR 就返回了登录页面 自已写一个拦截器类loginInterceptor implements HandlerInterceptor,实现preHandle方法,方法中如果验让不过直接 res.sendRedirect("jsp/loigin.jsp"); return false; 然后在配制文件中设置一下。<bean id="loginInterceptor" class="com.yy.LoginInterceptor"></bean><bean id="urlMapping" class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping"> <property name="interceptors"> <list> <ref bean="loginInterceptor" /> </list> </property> <property name="mappings"> <props> <prop key="aa.action">XXaction</prop> //添加要验让的其他请求 </props> </property> </bean> 1.可以写一个拦截器来来处理就,判断session中是否有该用户,若没有用户直接return Action.LOGIN(在这里举个例子回到登录页面了)。建议使用第一种方案。2.也可以在每个每个Action后台代码判断session中是否有该用户,若没有直接return “login”;public String save() throws Exception { Map session = ActionContext.getContext().getSession(); User user = (User) session.get("user"); if (user != null&&file!=null) { for (int i = 0; i <file.length; i++) { InputStream is = new FileInputStream(file[i]); String root = ServletActionContext.getRequest().getRealPath( "/photo"); File destFile = new File(root, this.fileFileName[i]); OutputStream os = new FileOutputStream(destFile); byte[] buffer = new byte[400]; int length = 0; while ((length = is.read(buffer)) > 0) { os.write(buffer, 0, length); } is.close(); os.close(); String path = "/BBS/photo/" + this.fileFileName[i]; session.put("path", path); Photo photo = new Photo(); photo.setDate(new Date().getTime()); photo.setPhoto_name(this.photo.getPhoto_name().get(i)); photo.setPhoto_introduce(this.photo.getPhoto_introduce().get(i)); photo.setPhoto_path(path); photo.setUser(user); HttpServletRequest request = ServletActionContext.getRequest(); request.setAttribute("photo", photo); photoService.save(photo); } return SUCCESS; } else return INPUT; } 我的意思是: 比如:我现在在csdn的下载页面,点击下载时它提示我没有登录,登录后就直接跳转到刚刚下载的页面 而没有跳转社区中心 我要实现的是这种功能 ????? 可以做一个通用的jsp页面,里面做判断,只要未登录就跳转到登录界面!然后所有的页面都包含这个jsp就可以了~~ 你们说的这种我会: 假如:一个用户登录后 就跳转到index.jsp 我现在在下载页面down.jsp 当我点击下载的时候提示我登录(所有的登录肯定都会跳转到index.jsp) 但是我现在想跳到down.jsp 这种功能怎么实现 自己写个拦截器 拦截session中的用户就可以了,没有就跳到登录 有就是继续下一个action 关于hibernate映射问题,映射不了 struts+spring报错org.springframework.beans.factory.BeanCreationException 请教:如何得到在jsp里得到当前服务器一共有多少个session? 新手求救:如何从地址栏登陆 jsp与javascript的简单问题(急) jspsmart的下载问题 JSP中import package 的问题 招聘 IDEA 连接数据库报错 JdbcTemplate什么时候注入的? 学习jsp的书 用ResultSet对象获取数据集中第n行的第n列值?
<result name="error">/login</result>/////原来的页面在你的action里面返回值 如果返回 SUCCESS 就跳转到了其他页面
如果返回了 ERROR 就返回了登录页面
return false; 然后在配制文件中设置一下。<bean id="loginInterceptor" class="com.yy.LoginInterceptor"></bean><bean id="urlMapping" class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping"> <property name="interceptors">
<list>
<ref bean="loginInterceptor" />
</list>
</property>
<property name="mappings">
<props>
<prop key="aa.action">XXaction</prop>
//添加要验让的其他请求
</props>
</property>
</bean>
2.也可以在每个每个Action后台代码判断session中是否有该用户,若没有直接return “login”;
public String save() throws Exception {
Map session = ActionContext.getContext().getSession();
User user = (User) session.get("user");
if (user != null&&file!=null) {
for (int i = 0; i <file.length; i++) {
InputStream is = new FileInputStream(file[i]);
String root = ServletActionContext.getRequest().getRealPath(
"/photo");
File destFile = new File(root, this.fileFileName[i]);
OutputStream os = new FileOutputStream(destFile);
byte[] buffer = new byte[400];
int length = 0;
while ((length = is.read(buffer)) > 0) {
os.write(buffer, 0, length);
}
is.close();
os.close();
String path = "/BBS/photo/" + this.fileFileName[i];
session.put("path", path);
Photo photo = new Photo();
photo.setDate(new Date().getTime());
photo.setPhoto_name(this.photo.getPhoto_name().get(i));
photo.setPhoto_introduce(this.photo.getPhoto_introduce().get(i));
photo.setPhoto_path(path);
photo.setUser(user);
HttpServletRequest request = ServletActionContext.getRequest();
request.setAttribute("photo", photo);
photoService.save(photo);
}
return SUCCESS;
} else
return INPUT;
}
我的意思是:
比如:我现在在csdn的下载页面,点击下载时它提示我没有登录,登录后就直接跳转到刚刚下载的页面 而没有跳转社区中心
我要实现的是这种功能 ?????
然后所有的页面都包含这个jsp就可以了~~
假如:一个用户登录后 就跳转到index.jsp
我现在在下载页面down.jsp 当我点击下载的时候提示我登录(所有的登录肯定都会跳转到index.jsp) 但是我现在想跳到down.jsp
这种功能怎么实现