[其它系统] 泛微Ecode新增Button调用服务器中的JSP页面里的方法

304 0
Honkers 2025-3-3 13:40:41 | 显示全部楼层 |阅读模式

前言

前端Ecode调用

后端接口编写

JSP文件方法

总结


前言

因为我们是从之前E8版本升级到E9的,所以会有一些接口是通过jsp文件来实现前后端调用的,这里介绍的就是如果你有接口是写在jsp文件里面调用的,但是你又想在Ecode中调用的对应的接口,那么继续往下看你就会明白具体该如何调用了

前端Ecode调用

  1. const { WeaTools, WeaSlideModal } = ecCom;
  2. class testComponent extends React.Component {
  3. constructor(props) {
  4. super(props);
  5. this.state = {
  6. info: {
  7. name: ''
  8. },
  9. jsonData: {},
  10. currentObj: {},
  11. xm: WfForm.getFieldValue(WfForm.convertFieldNameToId("xm"))
  12. };
  13. }
  14. componentDidMount() {
  15. window.WfCustomInfoRef = this;
  16. this.getData();
  17. }
  18. getData() {
  19. const data = {
  20. name: "John1",
  21. age: 25
  22. };
  23. fetch('http://IP:PORT/api/workflow/test/getInfo2', {
  24. method: 'POST',
  25. headers: {
  26. 'Content-Type': 'application/json'
  27. },
  28. body: JSON.stringify(data)
  29. })
  30. .then(response => response.json())
  31. .then(data => {
  32. this.setState({
  33. jsonData: data
  34. }, () => {
  35. console.log(this.state.jsonData);
  36. console.log("输出姓名值" + this.state.xm);
  37. });
  38. })
  39. .catch(error => {
  40. console.error('请求出错:', error);
  41. });
  42. }
  43. handleClick() {
  44. alert("ecode方法被点击");
  45. }
  46. render() {
  47. const { info, jsonData, currentObj } = this.state;
  48. return (
  49. <div>
  50. 添加的自定义内容2{jsonData.username}
  51. <SonComponent />
  52. <button onClick={()=>{
  53. var requestId = WfForm.getBaseInfo().requestid;
  54. jQuery.ajax({
  55. type: "POST",
  56. url: "http://IP:PORT/workflow/request/GetInfoDataAjax.jsp",
  57. data: {'requestid':requestId, 'method':"QZgd"},
  58. //dataType: 'json',
  59. success:function(data){
  60. console.log(data)
  61. // alert(data)
  62. },
  63. error:function(data){
  64. alert("系统出现问题,请联系管理员!");
  65. }
  66. })
  67. }}>按钮</button>
  68. {jsonData.test}
  69. </div>
  70. );
  71. }
  72. }
  73. ecodeSDK.setCom('${appId}', 'testComponent', testComponent);
复制代码

需要注意的是,可以直接在插入的按钮里编写点击事件,但是推荐最好就是定义一个方法,然后点击按钮的时候直接调用就可以了(因为我这里是做一个测试,所以就直接写上去了)

后端接口编写

  1. package com.jiuyi.info;
  2. import weaver.interfaces.workflow.action.WorkflowFnaInWorkflow;
  3. import org.apache.commons.logging.Log;
  4. import org.apache.commons.logging.LogFactory;
  5. public class TestGuiDang {
  6. private Log log = (Log) LogFactory.getLog(WorkflowFnaInWorkflow.class.getName());
  7. public String Qzgd(String requestId){
  8. this.log.info("TestGuiDang测试按钮点击接口的调用"+requestId);
  9. return "1";
  10. }
  11. }
复制代码

在这个class中编写你需要的代码即可,无论是更新数据还是返回信息都可以,只是你需要注意要将这个接口放到对应的jsp文件中引用

JSP文件方法

  1. <%@page import="net.sf.json.JSONObject"%>
  2. <%@ page language="java" contentType="text/html; charset=UTF-8" %>
  3. <%@page import="weaver.general.Util"%>
  4. <%@page import="com.sap.mw.jco.IFunctionTemplate"%>
  5. <%@page import="com.sap.mw.jco.JCO"%>
  6. <jsp:useBean id="rs" class="weaver.conn.RecordSet" scope="page"/>
  7. <%@page import="weaver.general.BaseBean"%>
  8. <%@page import="com.jiuyi.ajax.TestGuiDang"%>
  9. <%
  10. if(method.equals("QZgd")){
  11. TestGuiDang testGuiDan = new TestGuiDang();
  12. String requestId = Util.null2String(request.getParameter("requestid"));
  13. out.println("Request ID: " + requestId);
  14. out.println(testGuiDan.Qzgd(requestId));
  15. return;
  16. }
  17. %>
复制代码

在jsp文件中,你会有对应的方法名称来进行判断,然后只需要实例化对象然后传参调用即可

总结

建议最好还是直接采用E9的接口编写,那样的话轻松多了,可以直接通过接口传递参数而不用借助jsp文件来实现前后端的传参

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

Honkers

特级红客

关注
  • 3156
    主题
  • 36
    粉丝
  • 0
    关注
这家伙很懒,什么都没留下!

中国红客联盟公众号

联系站长QQ:5520533

admin@chnhonker.com
Copyright © 2001-2025 Discuz Team. Powered by Discuz! X3.5 ( 粤ICP备13060014号 )|天天打卡 本站已运行