分类: 嵌入式
2012-09-07 21:58:09
01 | public class LoginAction extends ActionSupport { |
02 |
03 | private static final long serialVersionUID = 1L; |
04 |
05 | private String account;//账号 |
06 | private String pwd;//密码 |
07 |
08 | public String login() throws Exception{ |
09 |
10 | //获取request |
11 | HttpServletRequest request=ServletActionContext.getRequest(); |
12 | //获取response |
13 | HttpServletResponse response=ServletActionContext.getResponse(); |
14 | //获取Session |
15 | HttpSession session=request.getSession(true); |
16 | //放到session中 |
17 | session.setAttribute("account", account); |
18 | //获得上下文 |
19 | ServletContext context=ServletActionContext.getServletContext(); |
20 | //获取upload文件夹 |
21 | File uploadFile=new File(context.getRealPath("upload")); |
22 |
23 | //给客户端返回结果 |
24 | PrintWriter writer=response.getWriter(); |
25 | writer.print("account"); |
26 |
27 | return execute(); |
28 | } |
29 | } |
01 | public class ServletAwareAction extends ActionSupport implements |
02 | ServletRequestAware, ServletResponseAware, SessionAware, ServletContextAware { |
03 |
04 | private static final long serialVersionUID = 1L; |
05 |
06 | private ServletContext application;//Servlet上下文 |
07 | private HttpServletRequest request;//request对象 |
08 | private HttpServletResponse response;//response对象 |
09 | private Map |
10 |
11 | public void setServletRequest(HttpServletRequest request) { |
12 | this.request=request; |
13 | } |
14 |
15 | public void setServletResponse(HttpServletResponse response) { |
16 | this.response=response; |
17 | } |
18 |
19 | public void setSession(Map |
20 | this.session=session; |
21 | } |
22 |
23 | public void setServletContext(ServletContext application) { |
24 | this.application=application; |
25 | } |
26 |
27 | public String execute(){ |
28 | String upload=application.getRealPath("upload"); |
29 |
30 | request.getRemoteAddr(); |
31 | response.getContentType(); |
32 | session.get("account"); |
33 |
34 | return Action.SUCCESS; |
35 | } |