例如:登录功能,如果登录成功,则跳转到WEB-INF/pages/main.jsp。如果失败,则还跳转至index.jsp
- package com.um.action;
-
-
- import java.util.List;
-
- import javax.servlet.http.HttpServletRequest;
-
- import org.nutz.ioc.loader.annotation.Inject;
- import org.nutz.ioc.loader.annotation.IocBean;
- import org.nutz.json.Json;
- import org.nutz.log.Log;
- import org.nutz.log.Logs;
- import org.nutz.mvc.View;
- import org.nutz.mvc.annotation.At;
- import org.nutz.mvc.annotation.By;
- import org.nutz.mvc.annotation.Fail;
- import org.nutz.mvc.annotation.Filters;
- import org.nutz.mvc.annotation.Ok;
- import org.nutz.mvc.annotation.Param;
- import org.nutz.mvc.view.JspView;
- import org.nutz.mvc.view.ViewWrapper;
-
- import com.um.model.User;
- import com.um.service.UserService;
-
-
- @IocBean(name="userAction",singleton=false)
- public class UserAction {
- private static Log log = Logs.get();
-
- @Inject
- private UserService userService;
-
- @At("/login")
- @Ok("->:/index.jsp")
- public View login(@Param("uid")String userid,@Param("pwd")String password,HttpServletRequest request){
- log.debug("userid:"+userid);
- log.debug("password:"+password);
- User user = userService.login(userid, password);
- if(user!=null) {
- request.getSession().setAttribute("userInfo", user);
- List<User> userList = userService.getUserList();
- request.setAttribute("userList", userList);
- return new JspView("pages.main");
- }
- return null;
- }
-
-
- }