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" ...
随机推荐
- 一: DRF web应用框架基础,及序列化器的使用
---恢复内容开始--- 一: web 应用模式(有两种) 1: 前后端不分离(前端从后端直接获取数据) 2: 前后端分离 二: api 接口 原因一: 为了在团队内部形成共识.防止个人习惯差异引起的 ...
- 『TensorFlow』张量尺寸获取
tf.shape(a)和a.get_shape()比较 相同点:都可以得到tensor a的尺寸 不同点:tf.shape()中a 数据的类型可以是tensor, list, array a.get_ ...
- grpc(三)之grpc客户端使用连接池
本文使用commons-pool2来实现连接池应用 1.定义一个产生连接池的工厂,需要继承BasePooledObjectFactory,其用处是生产和销毁连接池中保存的对象.根据需求,现在池子里保存 ...
- mysql和mariadb支持insert delayed的问题
分析一个开源项目,往数据库里添加日志,为了避免写入日志信息影响正常业务,日志的插入方式采用了insert delayed的方式. 打印其数据库语句,复制到mysql执行报如下错误: ERROR 161 ...
- node.js面试题大全-侧重后端应用与对Node核心的理解
Node是搞后端的,不应该被被归为前端,更不应该用前端的观点去理解,去面试node开发人员.所以这份面试题大全,更侧重后端应用与对Node核心的理解. github地址: https://github ...
- 【阅读笔记】《C程序员 从校园到职场》第六章 常用文件操作函数 (Part 1)
参考链接:https://blog.csdn.net/zhouzhaoxiong1227/article/details/24926023 让你提前认识软件开发(18):C语言中常用的文件操作函数总结 ...
- CSS3 2D转换 动画
transform:translate(x,y): 过度 鼠标悬浮 在2s内完成所有变化 div { width:100px; height:100px; background:red; trans ...
- angular2在ts中使用transform转换时间格式
摘要:在angular1中我们可以在控制器中像下面那样使用filter: $filter('date')(myDate, 'yyyy-MM-dd'); 但是如何在angular2中在ts中使用自定义p ...
- CodeForces - 589A (STL容器的使用)
Polycarp has quite recently learned about email aliases. Of course, he used to suspect that the case ...
- vue学习笔记 - 篇2
1.借助Vue.extend()方法创建组件 注意点 var Aaa = Vue.extend({ template: "<h1>这是标题</h1>" }) ...