我想有这样的场景,如果调用方法,方法内的代码将能够调用JavaScript方法在网页中显示弹出框。
我读了一些关于脚本引擎的内容,但我不确定它是否适用于这种情况。 或者我是否需要使用观察者模式(例如网络套接字)来监听任何事件?
// -------------------Create a Report-------------------------------------------
//This method is being called.
@SuppressWarnings("unchecked")
@RequestMapping(value = "/proposal/", method = RequestMethod.POST)
public ResponseEntity<?> createReport(@RequestBody Report report, UriComponentsBuilder ucBuilder) {
logger.info("Creating Report : {}", report);
if (reportRepository.isReportExist(report)) {
logger.error("Unable to create. A report with name {} already exist", report.getCrisisID());
return new ResponseEntity(new CustomErrorType("Unable to create. A Report with crisisID " +
report.getCrisisID() + " already exist."),HttpStatus.CONFLICT);
}
reportRepository.saveReport(report);
HttpHeaders headers = new HttpHeaders();
headers.setLocation(ucBuilder.path("/CMOtoPMO/proposal/{crisisID}").buildAndExpand(report.getCrisisID()).toUri());
//Code will call the javascript function to call show a pop up/alert box in my webpage
return new ResponseEntity<String>(headers, HttpStatus.CREATED);
}
答案 0 :(得分:0)
要致电JavaScript
,您可以使用javax.script
import javax.script.*;
...
ScriptEngineManager manager = new ScriptEngineManager();
ScriptEngine engine = manager.getEngineByName("JavaScript");
...
engine.eval(...);
更多信息here