怎么看網(wǎng)站日志文件軟件推廣怎么賺錢
前言
前端Ecode調(diào)用
后端接口編寫
JSP文件方法
總結(jié)
前言
因?yàn)槲覀兪菑闹癊8版本升級(jí)到E9的,所以會(huì)有一些接口是通過jsp文件來實(shí)現(xiàn)前后端調(diào)用的,這里介紹的就是如果你有接口是寫在jsp文件里面調(diào)用的,但是你又想在Ecode中調(diào)用的對(duì)應(yīng)的接口,那么繼續(xù)往下看你就會(huì)明白具體該如何調(diào)用了
前端Ecode調(diào)用
const { WeaTools, WeaSlideModal } = ecCom;class testComponent extends React.Component {constructor(props) {super(props);this.state = {info: {name: ''},jsonData: {},currentObj: {},xm: WfForm.getFieldValue(WfForm.convertFieldNameToId("xm"))};}componentDidMount() {window.WfCustomInfoRef = this;this.getData();}getData() {const data = {name: "John1",age: 25};fetch('http://IP:PORT/api/workflow/test/getInfo2', {method: 'POST',headers: {'Content-Type': 'application/json'},body: JSON.stringify(data)}).then(response => response.json()).then(data => {this.setState({jsonData: data}, () => {console.log(this.state.jsonData);console.log("輸出姓名值" + this.state.xm);});}).catch(error => {console.error('請(qǐng)求出錯(cuò):', error);});}handleClick() {alert("ecode方法被點(diǎn)擊");}render() {const { info, jsonData, currentObj } = this.state;return (<div>添加的自定義內(nèi)容2{jsonData.username}<SonComponent /><button onClick={()=>{var requestId = WfForm.getBaseInfo().requestid;jQuery.ajax({type: "POST",url: "http://IP:PORT/workflow/request/GetInfoDataAjax.jsp",data: {'requestid':requestId, 'method':"QZgd"},//dataType: 'json',success:function(data){console.log(data)// alert(data)},error:function(data){alert("系統(tǒng)出現(xiàn)問題,請(qǐng)聯(lián)系管理員!");}})}}>按鈕</button>{jsonData.test}</div>);}
}ecodeSDK.setCom('${appId}', 'testComponent', testComponent);
需要注意的是,可以直接在插入的按鈕里編寫點(diǎn)擊事件,但是推薦最好就是定義一個(gè)方法,然后點(diǎn)擊按鈕的時(shí)候直接調(diào)用就可以了(因?yàn)槲疫@里是做一個(gè)測試,所以就直接寫上去了)
后端接口編寫
package com.jiuyi.info;
import weaver.interfaces.workflow.action.WorkflowFnaInWorkflow;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;public class TestGuiDang {private Log log = (Log) LogFactory.getLog(WorkflowFnaInWorkflow.class.getName());public String Qzgd(String requestId){this.log.info("TestGuiDang測試按鈕點(diǎn)擊接口的調(diào)用"+requestId);return "1";}}
在這個(gè)class中編寫你需要的代碼即可,無論是更新數(shù)據(jù)還是返回信息都可以,只是你需要注意要將這個(gè)接口放到對(duì)應(yīng)的jsp文件中引用
JSP文件方法
<%@page import="net.sf.json.JSONObject"%>
<%@ page language="java" contentType="text/html; charset=UTF-8" %><%@page import="weaver.general.Util"%>
<%@page import="com.sap.mw.jco.IFunctionTemplate"%>
<%@page import="com.sap.mw.jco.JCO"%><jsp:useBean id="rs" class="weaver.conn.RecordSet" scope="page"/>
<%@page import="weaver.general.BaseBean"%><%@page import="com.jiuyi.ajax.TestGuiDang"%><%if(method.equals("QZgd")){TestGuiDang testGuiDan = new TestGuiDang();String requestId = Util.null2String(request.getParameter("requestid"));out.println("Request ID: " + requestId); out.println(testGuiDan.Qzgd(requestId));return;
}%>
在jsp文件中,你會(huì)有對(duì)應(yīng)的方法名稱來進(jìn)行判斷,然后只需要實(shí)例化對(duì)象然后傳參調(diào)用即可
總結(jié)
建議最好還是直接采用E9的接口編寫,那樣的話輕松多了,可以直接通過接口傳遞參數(shù)而不用借助jsp文件來實(shí)現(xiàn)前后端的傳參