Java Code Examples for com.opensymphony.xwork2.ActionContext#getContext()
The following examples show how to use
com.opensymphony.xwork2.ActionContext#getContext() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Form1Action.java From Project with Apache License 2.0 | 6 votes |
@Override public String execute() throws Exception{ // 使用 Struts 中 ActionContext 对象接收表单的参数 ActionContext actionContext = ActionContext.getContext(); // 接收参数 HttpParameters paramsMap = actionContext.getParameters(); for(String key : paramsMap.keySet()){ String value = paramsMap.get(key).getValue(); } // 向 request 中存入数据 : request.setAttribute(String name, Object value); actionContext.put("requestName","requestGJXAIOU"); // 向 session 中存入数据: request.getSession().setAttribute(String name, Object value); actionContext.put("sessionName", "sessionGJXAIOU"); // 向 application 中存入数据 this.getServletContext().setAttribute(String name, Object value); actionContext.getApplication().put("applicationName", "applicationGJXAIOU"); return SUCCESS; }
Example 2
Source File: authInterceptor.java From Mall-Server with MIT License | 6 votes |
@Override public String intercept(ActionInvocation actionInvocation) throws Exception { String token = ServletActionContext.getRequest().getHeader("x-access-token"); if (token != null) { User user = Token.validToken(token, User.class); if (user != null) { ServletActionContext.getRequest().setAttribute("tokenData", user); actionInvocation.invoke(); return null; } } ActionContext context = ActionContext.getContext(); ValueStack stack = context.getValueStack(); stack.set("jsonResult", ResponseTemplate.error(1, "请传输正确token")); return "success"; }
Example 3
Source File: postInterceptor.java From Mall-Server with MIT License | 6 votes |
/** * 只允许POST访问拦截器 * @param actionInvocation * @return * @throws Exception */ @Override public String intercept(ActionInvocation actionInvocation) throws Exception { // 解决跨域 HttpServletResponse res = ServletActionContext.getResponse(); res.setHeader("Access-Control-Allow-Origin", "*"); res.setHeader("Access-Control-Allow-Credentials", "true"); res.setHeader("Access-Control-Allow-Methods", "*"); res.setHeader("Access-Control-Allow-Headers", "Content-Type,Access-Token"); res.setHeader("Access-Control-Expose-Headers", "*"); String method = ServletActionContext.getRequest().getMethod(); if (method.equals("POST")) { actionInvocation.invoke(); return null; } else { ActionContext context = ActionContext.getContext(); Map<String, Object> jsonResult = new HashMap<String, Object>(); jsonResult.put("rcode", 1); jsonResult.put("message", "just allow post method"); jsonResult.put("result", ""); ValueStack stack = context.getValueStack(); stack.set("jsonResult", jsonResult); return "success"; } }
Example 4
Source File: FileManagerDaoImpl.java From scada with MIT License | 6 votes |
public void delete(Integer id){ ActionContext actionContext = ActionContext.getContext(); Map<String, Object> session = actionContext.getSession(); String select=(String) session.get("select"); String message=(String) session.get("message"); if(!message.equals("")){ if(select.equals("id")){ try{ FileManager fileManager=(FileManager)this.getSessionFactory().openSession().get(FileManager.class, id); this.getHibernateTemplate().delete(fileManager); this.getSessionFactory().openSession().close(); }catch(Exception e){ System.out.println(e); } } } }
Example 5
Source File: UserAction.java From Project with Apache License 2.0 | 5 votes |
@Override public String execute() throws Exception { // 1.获取 ActionContext 类的对象 ActionContext actionContext = ActionContext.getContext(); // 2.调用方法获取值栈对象 ValueStack valueStack = actionContext.getValueStack(); // 验证每个 Action 对象只有一个值栈对象 ValueStack valueStack1 = actionContext.getValueStack(); System.out.println(valueStack == valueStack1); return NONE; }
Example 6
Source File: ValueStackAction.java From Project with Apache License 2.0 | 5 votes |
@Override public String execute() throws Exception { ActionContext actionContext = ActionContext.getContext(); ValueStack valueStack = actionContext.getValueStack(); return SUCCESS; }
Example 7
Source File: MeetManagerDaoImpl.java From scada with MIT License | 5 votes |
@Override public void updateAndDelete(int id) { ActionContext actionContext = ActionContext.getContext(); Map<String, Object> session = actionContext.getSession(); String select=(String) session.get("select"); String message=(String) session.get("message"); Connection conn=null; String sql=null; if(!message.equals("")){ if(select.equals("id")){ try{ conn=getConnection(); sql="UPDATE `scada`.`meet_room` SET `useful`='����' WHERE `meetroom_id`="+"'"+id+"'"; PreparedStatement ps = (PreparedStatement) conn.prepareStatement(sql); ps.executeUpdate(); //MeetManager meetManager=(MeetManager)this.getSessionFactory().openSession().get(MeetManager.class, id); //this.getHibernateTemplate().delete(meetManager); //this.getSessionFactory().openSession().close(); conn.close(); conn=null; System.out.println(conn); }catch(Exception e){ System.out.println(e); } } } }
Example 8
Source File: MeetManagerDaoImpl.java From scada with MIT License | 5 votes |
@Override public void delete(String mess){ ActionContext actionContext = ActionContext.getContext(); Map<String, Object> session = actionContext.getSession(); String select=(String) session.get("select"); String message=(String) session.get("message"); int id =Integer.valueOf(mess); /* Connection conn=null; String sql=null; try{ conn=getConnection(); sql="DELETE FROM `big_project`.`meet_manager` WHERE `meet_id`="+"'"+id+"'"; PreparedStatement ps = (PreparedStatement) conn.prepareStatement(sql); ps.executeUpdate(); conn.close(); conn=null; }catch(Exception e){ //e.printStackTrace(); } */ if(!message.equals("")){ if(select.equals("id")){ try{ MeetManager meetManager=(MeetManager)this.getSessionFactory().openSession().get(MeetManager.class, id); this.getHibernateTemplate().delete(meetManager); this.getSessionFactory().openSession().close(); }catch(Exception e){ System.out.println(e); } } } }
Example 9
Source File: MeetManagerDaoImpl.java From scada with MIT License | 4 votes |
@Override public void save() { Connection conn=null; try { ActionContext actionContext = ActionContext.getContext(); Map<String, Object> session = actionContext.getSession(); String []file=new String[10]; /*****************************************************/ file[0]=(String) session.get("meet_id"); file[1]=(String) session.get("meet_name"); file[2]=(String) session.get("meet_title"); file[3]=(String) session.get("meet_content"); file[4]=(String) session.get("people_num"); file[5]=(String) session.get("start_end"); file[6]=(String) session.get("location"); file[7]=(String) session.get("meetroom_num"); file[8]=(String) session.get("useful_time"); file[9]=(String) session.get("room_size"); int meet_id=Integer.valueOf(file[0]); int people_num=Integer.valueOf(file[4]); int meetroom_num=Integer.valueOf(file[7]); int room_size=Integer.valueOf(file[9]); /*****************************************************/ conn=getConnection(); String sql= "INSERT INTO `scada`.`meet_manager` (`meet_id`, `meet_name`, `meet_title`, `meet_content`, `people_num`, `start_end`, `location`, `meetroom_num`, `useful_time`, `room_size`) " + "VALUES ("+"'"+meet_id+"', '"+file[1]+"', '"+file[2]+"', '"+file[3]+"', '"+people_num+"', '"+file[5]+"', '"+file[6]+"', '"+meetroom_num+"', '"+file[8]+"', '"+room_size+"');"; PreparedStatement ps = (PreparedStatement) conn.prepareStatement(sql); int row = ps.executeUpdate(); if(row > 0) System.out.println("�ɹ������" + row + "������"); conn.close(); conn=null; }catch(Exception e){ e.printStackTrace(); } }
Example 10
Source File: FileManagerDaoImpl.java From scada with MIT License | 4 votes |
@Override public void save() { try { ActionContext actionContext = ActionContext.getContext(); Map<String, Object> session = actionContext.getSession(); int j = 1; String []file=new String[20]; file[0]=(String) session.get("sname"); file[1]=(String) session.get("identity_card"); file[2]=(String) session.get("sex"); file[3]=(String) session.get("both"); file[4]=(String) session.get("age"); file[5]=(String) session.get("location"); file[6]=(String) session.get("zip_code"); file[7]=(String) session.get("nation"); file[8]=(String) session.get("politics_status"); file[9]=(String) session.get("school"); file[10]=(String) session.get("education_background"); file[11]=(String) session.get("major"); file[12]=(String) session.get("job_title"); file[13]=(String) session.get("job_title_date"); file[14]=(String) session.get("qualification"); file[15]=(String) session.get("telephone"); file[16]=(String) session.get("mobilephone"); file[17]=(String) session.get("urgent_phone"); file[18]=(String) session.get("company_email"); file[19]=(String) session.get("sole_email"); int age=Integer.valueOf(file[4]); Class.forName("com.mysql.jdbc.Driver"); String url = "jdbc:mysql://localhost:3306/scada"; String username = "root"; String password = "root"; Connection conn = (Connection) DriverManager.getConnection(url , username , password); if (conn != null) System.out.println("���ݿ����ӳɹ�!"); else System.out.println("���ݿ�����ʧ��!"); //��ɺ�ǵùر����ݿ����� String sql_1="SELECT `sid` FROM `scada`.`file_manager`;"; PreparedStatement ps_1 = (PreparedStatement) conn.prepareStatement(sql_1); ResultSet s_1=ps_1.executeQuery(); int sid; while(s_1.next()){ sid =s_1.getInt(1); System.out.println(sid); if(sid==0) { System.out.println(sid); }else j=sid+1; } /*String sql_2="SELECT `identity_card` FROM `big_project`.`file_manager` WHERE identity_card="+"'"+file[1]+"';"; PreparedStatement ps_2 = (PreparedStatement) conn.prepareStatement(sql_2); ResultSet s_2=ps_2.executeQuery(); System.out.println(6); if(s_2==null){ System.out.println(7);*/ String sql= "INSERT INTO `scada`.`file_manager` (`sid`, `sname`, `identity_card`, `sex`, `both`, `age`, `location`, `zip_code`, `nation`, `politics_status`, `school`, `education_background`, `major`, `job_title`, `job_title_date`, `qualification`, `telephone`, `mobilephone`, `urgent_phone`, `company_email`, `sole_email`) " + "VALUES ('"+j+"', "+"'"+file[0]+"', '"+file[1]+"', '"+file[2]+"', '"+file[3]+"', '"+age+"', '"+file[5]+"', '"+file[6]+"', '"+file[7]+"', '"+file[8]+"', '"+file[9]+"', '"+file[10]+"', '"+file[11]+"', '"+file[12]+"', '"+file[13]+"', '"+file[14]+"', '"+file[15]+"', '"+file[16]+"', '"+file[17]+"', '"+file[18]+"', '"+file[19]+"');"; PreparedStatement ps = (PreparedStatement) conn.prepareStatement(sql); int row = ps.executeUpdate(); if(row > 0) System.out.println("�ɹ������" + row + "������"); //}else{ conn.close(); conn=null; //} }catch(Exception e){ System.out.println(e); } }
Example 11
Source File: AchievementAction.java From scada with MIT License | 4 votes |
/*******addFile�IJ���*******/ public String Achievement(){ int id; ActionContext actionContext = ActionContext.getContext(); Map<String, Object> session = actionContext.getSession(); session.put("select", select); session.put("message", message); session.put("swit", swit); session.put("information", information); /*******addFile��Session*******/ /*******addFile��Session*******/ if(swit!=null){ switch(swit){ case "������Ϣ": { if(message!=""){ request.put("achievement", achievementService.Search()); request.put("infors", achievementService.getAllinformation()); return "Achievement"; }else{ request.put("infors", achievementService.getAllinformation()); return "Achievement"; } } case "ɾ����Ϣ":{ if(message.equals("")||select.equals("name")||select.equals("card")){ request.put("achievement", achievementService.getAll()); request.put("infors", achievementService.getAllinformation()); return "Achievement"; }else{ id=Integer.valueOf(message); achievementService.delete(id); request.put("achievement", achievementService.getAll()); request.put("infors", achievementService.getAllinformation()); return "Achievement"; } } case "�ύ": { achievementService.save(); request.put("achievement", achievementService.getAll()); request.put("infors", achievementService.getAllinformation()); return "Achievement"; } default: { achievementService.save(); request.put("achievement", achievementService.getAll()); request.put("infors", achievementService.getAllinformation()); return "Achievement"; } } }else{ request.put("achievement", achievementService.getAll()); request.put("infors", achievementService.getAllinformation()); return "Achievement"; } }
Example 12
Source File: FileManagerAction.java From scada with MIT License | 4 votes |
/*******addFile�IJ���*******/ public String FileManager()throws Exception{ int id; ActionContext actionContext = ActionContext.getContext(); Map<String, Object> session = actionContext.getSession(); session.put("select", select); session.put("message", message); /*******addFile��Session*******/ session.put("sname", sname); session.put("sex", sex); session.put("age", age); session.put("identity_card", identity_card); session.put("both", both); session.put("location", location); session.put("zip_code", zip_code); session.put("nation", nation); session.put("politics_status", politics_status); session.put("school", school); session.put("major", major); session.put("education_background", education_background); session.put("job_title", job_title); session.put("job_title_date", job_title_date); session.put("qualification", qualification); session.put("telephone", telephone); session.put("mobilephone", mobilephone); session.put("urgent_phone", urgent_phone); session.put("company_email", company_email); session.put("sole_email", sole_email); /*******addFile��Session*******/ if(swit!=null){ switch(swit){ case "������Ϣ": { if(message!=""){ request.put("fileManager", fileManagerService.Search()); return "FileManager"; }else{ return "FileManager"; } } case "ɾ����Ϣ":{ if(message.equals("")||select.equals("name")||select.equals("card")){ request.put("fileManager", fileManagerService.getAll()); return "FileManager"; }else{ id=Integer.valueOf(message); fileManagerService.delete(id); request.put("fileManager", fileManagerService.getAll()); return "FileManager"; } } case "�ύ": { if(!sname.equals("")&&!sex.equals("")&&!age.equals("")&&!both.equals("") &&!identity_card.equals("")&&!zip_code.equals("") &&!location.equals("")&&!nation.equals("")&&!politics_status.equals("") &&!school.equals("")&&!major.equals("")&&!education_background.equals("") &&!job_title.equals("")&&!job_title_date.equals("")&&!qualification.equals("") &&!mobilephone.equals("")&&!company_email.equals("")&&!sole_email.equals("") ){ fileManagerService.save(); request.put("fileManager", fileManagerService.getAll()); return "FileManager"; }else{ request.put("fileManager", fileManagerService.getAll()); return "FileManager"; } } default: { fileManagerService.save(); request.put("fileManager", fileManagerService.getAll()); return "FileManager"; } } }else{ request.put("fileManager", fileManagerService.getAll()); return "FileManager"; } }
Example 13
Source File: Pdf2Swf.java From csustRepo with MIT License | 4 votes |
public static Boolean pdf2Swf(String spath,String dpath,Integer pageSize){ File pdfFile = new File(spath); File swfFile = new File(dpath); Runtime r = Runtime.getRuntime(); if(pageSize==null){ pageSize=20; } if (!swfFile.exists()) { if (pdfFile.exists()) { try { ActionContext ac = ActionContext.getContext(); HttpServletRequest request =(HttpServletRequest)ac.get(ServletActionContext.HTTP_REQUEST); /*Process p = r.exec(request.getRealPath("/thirdparty/officetranslate/tools/pdf2swf.exe") + " " + pdfFile.getPath() + " -o " + swfFile.getPath() + " -T9" + " -p 1-"+pageSize);*/ StringBuilder commandBuilder=new StringBuilder( request.getSession().getServletContext().getRealPath( "/thirdparty/officetranslate/tools/pdf2swf.exe")); commandBuilder.append(" "); commandBuilder.append(pdfFile.getPath()); commandBuilder.append(" -o "); commandBuilder.append(swfFile.getPath()); commandBuilder.append(" -T9 "); commandBuilder.append(" -p 1-"); commandBuilder.append(pageSize); /*String command=request.getSession() .getServletContext().getRealPath( "/thirdparty/officetranslate/tools/pdf2swf.exe") +" " +pdfFile.getPath() +" -o " +swfFile.getPath() +" -T9 " +"";*/ //command= command.toString().replace("\\", "//"); System.out.println(commandBuilder.toString()); Process p=r.exec(commandBuilder.toString()); /*BufferedReader bufferedReader=new BufferedReader(new InputStreamReader(p.getInputStream())); String s=null; while((s=bufferedReader.readLine())!=null){ try { p.waitFor(); } catch (InterruptedException e) { // TODO Auto-generated catch block e.printStackTrace(); return false; } }*/ p.waitFor(); System.out.println("转换成功"); return true; } catch (Exception e) { e.printStackTrace(); try { throw e; } catch (Exception e1) { // TODO Auto-generatedcatch block e1.printStackTrace(); return false; } } } else { System.out.println("PDF文件不存在,无法转换"); return false; } } else { System.out.println("已经转为SWF文件,无需再次转换"); } /*if (pdfFile.exists()) { pdfFile.delete(); }*/ System.out.println("转换成功!!"); return true; //HttpSession session = request.getSession(); //session.setAttribute("fileName", swfFile.getName()); //response.sendRedirect(request.getContextPath() // + "/preview/flexpaper/readFile.jsp"); }
Example 14
Source File: BaseAction.java From csustRepo with MIT License | 4 votes |
public ActionContext getActionContext() { return ActionContext.getContext(); }
Example 15
Source File: AchievementDaoImpl.java From scada with MIT License | 2 votes |
@Override public void save() { ActionContext actionContext = ActionContext.getContext(); Map<String, Object> session = actionContext.getSession(); String infor=(String) session.get("information"); try{ Class.forName("com.mysql.jdbc.Driver"); String url = "jdbc:mysql://localhost:3306/scada"; String username = "root"; String password = "root"; Connection conn = (Connection) DriverManager.getConnection(url , username , password); if (conn != null) System.out.println("���ݿ����ӳɹ�!"); else System.out.println("���ݿ�����ʧ��!"); String sql_1="SELECT `id` FROM `scada`.`information`;"; PreparedStatement ps_1 = (PreparedStatement) conn.prepareStatement(sql_1); ResultSet s_1= ps_1.executeQuery(); int id=0; while(s_1.next()){ id =s_1.getInt("id"); } int id_1=id+1; String sql_2="INSERT INTO `scada`.`information` (`id`,`text`) VALUES ('"+id_1+"','"+infor+"')"; PreparedStatement ps = (PreparedStatement) conn.prepareStatement(sql_2); int row = ps.executeUpdate(); if(row > 0) System.out.println("�ɹ������" + row + "������"); conn.close(); conn=null; }catch(Exception e){ e.printStackTrace(); } }