java 从一个工程action 跳转到另外一个工程action
实现功能:java 从一个工程action 跳转到另外一个工程action
在我们实际编程的过程中,大家一定遇到过这种情况,那就是在一个工程中,需要使用到另外一个工程的实体Bean和方法。那么遇到这种情况我们应该怎么处理呢?就可以采用下面这种方法,将工程一中的参数传到工程二中来使用。最后得到我们需要的结果。详情代码如下:
工程一action:
@Controller
@RequestMapping("/conferences.do")
public class ConferencesAction extends BasicAction implements ServletContextAware{
private ConferencesService conferencesService;
private ServletContext servletContext;
private AdminuserOperatingService adminuserOperatingService;
private AdminuserService adminuserService;
private AdminuserConferencesService adminuserConferencesService;
private ClientVersionService clientVersionService;
private DataService dataService;
private SpeakerService speakerService;
private SessiongroupService sessiongroupService;
private CheckCodesChyService checkCodesChyService;
private EsmoService esmoService;
//课件信息统计
@RequestMapping(params = "method=getKeJianCount",method = RequestMethod.GET)
public void getKeJianCount(String[] bank2,String startTime,String endTime,ModelMap model,HttpServletRequest request,HttpServletResponse response)
{
try {
JSONObject result = new JSONObject();
String bank2String = "";
int bank2Length = bank2.length;
int state = 0;
if(bank2Length != 0){
for (int i = 0; i < bank2Length; i++) {
bank2String = bank2[i]+",";
}
int bank2StringLength = bank2String.length();
bank2String = bank2String.substring(0, (bank2StringLength-1));
HashMap<String,String> map = new HashMap<String, String>();
String url = request.getScheme()+"://"+request.getServerName()+":"+request.getLocalPort()+"/Exam";
startTime = URLEncoder.encode(startTime,"UTF-8");
endTime = URLEncoder.encode(endTime,"UTF-8");
HttpUtils httpUtils = new HttpUtils();
map.put("method", "getKeJianCount1");
map.put("bank2", bank2String);
map.put("startTime", startTime);
map.put("endTime", endTime);
String jsonString = httpUtils.httpGet(url+"/data", map);
JSONObject jsObject = JSONObject.fromObject(jsonString);
result.accumulate("url", jsObject.getString("url"));
state = 1;
result.accumulate("state", state);
writeToJson(response, result.toString());
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
工程二action:
@Controller
@RequestMapping("/data")
public class DataAction extends BasicAction{ @Resource(name="dataService")
private DataService dataService; //课件信息统计
@RequestMapping(params = "method=getKeJianCount1",method = RequestMethod.GET)
public void getKeJianCount1(String startTime,String endTime,ModelMap model,HttpServletRequest request,HttpServletResponse response)
{
String urlPath = request.getScheme()+"://"+request.getServerName()+request.getContextPath();
XSSFWorkbook rwb1 = new XSSFWorkbook();
while(true)
{
if(rwb1.getNumberOfSheets() != 0){
rwb1.removeSheetAt(0);
}
else{
break;
}
}
try {
String bank2 = request.getParameter("bank2");
String[] keJianTypeArray = bank2.split(",");
XSSFSheet ws1 = rwb1.createSheet("课件统计");
ws1.addMergedRegion(new CellRangeAddress(0, 1, 0, 0));
ws1.addMergedRegion(new CellRangeAddress(0, 1, 1, 1));
ws1.addMergedRegion(new CellRangeAddress(0, 1, 2, 2));
int count = 0;//行
XSSFRow row1 = ws1.createRow(count);
row1.createCell(0).setCellValue("课件类别");
row1.createCell(1).setCellValue("课件标题");
row1.createCell(2).setCellValue("课件作者");
row1.createCell(3).setCellValue("APP");
count++;
XSSFRow row4 = ws1.createRow(count);
row4.createCell(3).setCellValue("总点击次数"); if(keJianTypeArray != null){
int keJianTypeArrayLength = keJianTypeArray.length;
//1、遍历model_id 数组
for (int i = 0; i < keJianTypeArrayLength; i++) {
int modelId = Integer.valueOf(keJianTypeArray[i]);
String keJianType = modelId == 40?"CSCO年会 2016": modelId == 31?"CSCO年会 2017":modelId == 42 ?"BOA 2017":modelId == 39?"CSCO指南会 2017":"CSCO免疫肿瘤高峰论坛 2017";
//根据modelId查询某个课件类别的总点击量
int tatolClickNum = dataService.countKeJianTatolNumByModelId(modelId,startTime,endTime);
count++;
XSSFRow row2 = ws1.createRow(count);
row2.createCell(0).setCellValue(keJianType);
row2.createCell(1).setCellValue("所有课件总和");
row2.createCell(3).setCellValue(tatolClickNum);
//2、根据model_id 来查询资源集合
List<Data> dataList = dataService.getDataListByModelId(modelId);
//3、遍历得到的资源集合 得到统计数据
if(dataList != null && dataList.size() != 0){
for (Data data : dataList) {
Integer dataId = data.getDataId();
String keJianTitle = data.getTitle();
String keJianAuthor = data.getAuthor();
//4、根据dataId统计被点击的次数
int clickNum = dataService.countKeJianNumByDataId(dataId,startTime,endTime);
count++;
XSSFRow row3 = ws1.createRow(count);
row3.createCell(0).setCellValue(keJianType);
row3.createCell(1).setCellValue(keJianTitle);
row3.createCell(2).setCellValue(keJianAuthor);
row3.createCell(3).setCellValue(clickNum);
}
}
}
}
String filePath = request.getSession().getServletContext().getRealPath("files/execl");
File conFile = new File(filePath); //目录结构
if(!conFile.exists())
{
conFile.mkdir();
}
String fileName = "keJianCount.xlsx";
File file = new File(filePath+"/"+fileName);
if(file.exists())
{
file.delete();
}
else{
file.createNewFile();
}
FileOutputStream fout = new FileOutputStream(file);
rwb1.write(fout);
fout.close();
JSONObject jsonObject = new JSONObject();
jsonObject.accumulate("url",urlPath+"/files/execl/"+fileName);
writejson(response, jsonObject.toString());
} catch (Exception e) {
e.printStackTrace();
}
}
}
工具类:
public class HttpUtils {
public static String httpGet(String urlAddress,Map<String, String> paramMap){
if(paramMap==null){
paramMap = new HashMap<String, String>();
}
String [] params = new String[paramMap.size()];
int i = 0;
for(String paramKey:paramMap.keySet()){
String param = paramKey+"="+paramMap.get(paramKey);
params[i] = param;
i++;
}
return httpGet(urlAddress, params);
}
public static String httpGet(String urlAddress,String []params){
URL url = null;
HttpURLConnection con =null;
BufferedReader in = null;
StringBuffer result = new StringBuffer();
try {
String paramsTemp = "";
for(String param:params){
if(param!=null&&!"".equals(param.trim())){
paramsTemp+="&"+param;
}
}
if(paramsTemp.length() >0){
urlAddress = urlAddress+"?"+paramsTemp.substring(1,paramsTemp.length());
}
System.out.println(urlAddress);
url = new URL(urlAddress);
con = (HttpURLConnection) url.openConnection();
con.setUseCaches(false);
con.setRequestProperty("Cookie", "");
con.setRequestProperty("Connection", "Keep-Alive");
con.setRequestProperty("User-agent", " Mozilla/5.0 (Windows NT 6.1; WOW64; rv:33.0) Gecko/20100101 Firefox/33.0");
in = new BufferedReader(new InputStreamReader(con.getInputStream(),"utf-8"));
while (true) {
String line = in.readLine();
System.out.println(line);
if (line == null) {
break;
}
else {
result.append(line);
}
}
} catch (IOException e) {
e.printStackTrace();
}finally{
try {
if(in!=null){
in.close();
}
if(con!=null){
con.disconnect();
}
} catch (IOException e) {
e.printStackTrace();
}
}
return result.toString();
}
}
工具类的测试方法:
public static void main(String[] args) {
HashMap<String, String> param = new HashMap<String, String>();
param.put("id", "7102");
try {
param.put("giveName", URLEncoder.encode("ghris zhang","utf-8"));
} catch (Exception e) {
e.printStackTrace();
}
param.put("language", "en");
String result = HttpUtils.httpPost("http://reg.csco.org.cn/reg2015/io/check.asp", param);
System.out.println(result);
/*String enResult = "";
byte[] b = Base64.decodeFast("eyJpZCI6MTcwMCwibmFtZSI6IgAAACIsImdpdmVOYW1lIjoiAAAAIiwiZmFtaWx5TmFtZSI6InpoYW5ndGllYmlhbyIsIm1vYmlsZSI6IjE1MjIxNjUzNDAwIiwiZW1haWwiOiIyNzY3MzkyNzFAcXEuY29tIiwiYWRkcmVzcyI6IgAAAAAiLCJqb2JUaXRsZSI6IgAAIiwiRGVwYXJ0bWVudCI6IgAAIiwicGF5U3RhdGUiOjAsImlzbWVtYmVyIjowLCJzdGF0ZSI6MSwibXNnIjoiT0sifQ==");
List<Byte> bList = new ArrayList<Byte>();
try{
for (byte c : b) {
if(c != 0){
bList.add(c);
}
}
byte [] b1 = new byte[bList.size()];
for (int i = 0;i < bList.size();i++) {
b1[i] = bList.get(i);
}
enResult = new String(b1, "utf-8");
JSONObject json = JSONObject.fromObject(enResult);
System.out.println(json);
}catch(Exception e) {
e.printStackTrace();
} */
}
宽容别人,就是肚量;谦卑自己,就是份量;合起来,就是一个人的质量。
java 从一个工程action 跳转到另外一个工程action的更多相关文章
- struts2 从一个action跳转到另一个action的struts.xml文件的配置
解释: 想要用<result>跳转到另一个action,原来的配置代码是: <action name="insertDept" class="strut ...
- play的action链(一个action跳转到另一个action,类似于重定向)
在play中没有Servlet API forward 的等价物.每一个HTTP request只能调用一个action.如果我们需要调用另一个,必须通过重定向,让浏览器访问另一个URL来访问它.这样 ...
- Egret白鹭开发微信小游戏程序跳转功能(由一个小游戏跳转到另一个小游戏)
假设我们要实现的功能是从小游戏A跳转到小游戏B 对于小游戏A: (1)在platform.ts中添加代码如下: /** * 平台数据接口. * 由于每款游戏通常需要发布到多个平台上,所以提取出一个统一 ...
- Qt中实现点击一个label,跳转到打开一个浏览器链接
配置模块 首先需要在.pro配置文件中添加QT += network 重写自定义Label .h文件 class MyClickLabel : public QLabel { Q_OBJECT pub ...
- windows server 证书的颁发与IIS证书的使用 Dapper入门使用,代替你的DbSQLhelper Asp.Net MVC中Action跳转(转载)
windows server 证书的颁发与IIS证书的使用 最近工作业务要是用服务器证书验证,在这里记录下一. 1.添加服务器角色 [证书服务] 2.一路下一步直到证书服务安装完成; 3.选择圈选 ...
- C# MVC 用户登录状态判断 【C#】list 去重(转载) js 日期格式转换(转载) C#日期转换(转载) Nullable<System.DateTime>日期格式转换 (转载) Asp.Net MVC中Action跳转(转载)
C# MVC 用户登录状态判断 来源:https://www.cnblogs.com/cherryzhou/p/4978342.html 在Filters文件夹下添加一个类Authenticati ...
- Struts2 : action跳转时带参数跳转
在实现action跳转到另一个action时,需要携带参数,可以直接在struts.xml配置文件中对应的跳转action的地方加上,参数的配置,用ognl表达式,可以从session中取值. 如果要 ...
- Struts2 从一个Action跳至另一个Action
Struts2 从一个Action跳至另一个Action 一.注解的 @Result(name=SUCCESS,type="chain", params={"actio ...
- Spring MVC 中采用注解方式 Action中跳转到另一个Action的写法
Spring MVC 中采用注解方式 Action中跳转到另一个Action的写法 在Action中方法的返回值都是字符串行,一般情况是返回某个JSP,如: return "xx" ...
随机推荐
- 雷林鹏分享:jQuery EasyUI 数据网格 - 列运算
jQuery EasyUI 数据网格 - 列运算 在本教程中,您将学习如何在可编辑的数据网格(datagrid)中包含一个运算的列.一个运算列通常包含一些从一个或多个其他列运算的值. 首先,创建一个可 ...
- 网络模型 —— OSI七层模型,TCP五层模型,以及区分
1. OSI七层模型 OSI层 介绍 功能 TCP/IP协议 应用层 操作系统或网络应用程序提供访问网络服务的接口. 文件传输.浏览器.电子邮件 HTTP, FTP, TFTP, SNMP, DNS ...
- css新单位vw,vh在响应式设计中的应用
考虑到未来响应式设计的开发,如果你需要,浏览器的高度也可以基于百分比值调整.但使用基于百分比值并不总是相对于浏览器窗口的大小定义的最佳方式,比如字体大小不会随着你窗口改变而改变,如今css3引入的新单 ...
- Xgboost: 一把屠龙刀的自我修养
目录 引言 Xgboost 参考文献 引言 集成学习, 在机器学习中是一个非常重要的思想: 把多个弱分类器精巧地组合在一起,成为一个很强大的学习器. 集成学习也因此一直处在风口浪边. 集成学习主要分为 ...
- node 安装 webpack
首先要安装 Node.js, Node.js 自带了软件包管理器 npm,Webpack 需要 Node.js v0.6 以上支持,建议使用最新版 Node.js. 用 npm 安装 Webpack: ...
- restful : 面向资源架构
restful 规范 1. API与用户的通信协议,https协议 2. 域名 https://api.example.com 尽量将API部署在专用域名 https://example.org/ap ...
- 【转】Ubuntu英文系统下安装中文输入法
转自:https://my.oschina.net/No5stranger/blog/290026 ubuntu默认的输入法是ibus,综合网上评论,fcitx的支持者更多,而且个人感觉fcitx也的 ...
- django中的ORM介绍和字段及字段参数
Object Relational Mapping(ORM) ORM介绍 ORM概念 对象关系映射(Object Relational Mapping,简称ORM)模式是一种为了解决面向对象与关系数据 ...
- Quartz定时器+Spring + @Autowired注入 空指针异常
在Quartz的定时方法里引用@Autowired注入Bean,会报空指针错误 解决办法: 第一种方法:(推荐,简单,亲测可行) 使用@Resource(name="指定要注入的Bean&q ...
- MegaCli 简易使用介绍
查看帮助 MegaCli64 -h 适配卡配置 查看RAID控制器的数量 MegaCli64 -adpCount 查看所有raid卡详细信息 MegaCli64 -AdpAllInfo -aALL 查 ...