简体   繁体   English

jsp页面加载后如何动态加载更多的数据?

[英]How to dynamically load more data to the jsp page after it's loaded?

I have a problem here.我这里有问题。

Pre-problem前置问题

I am frontend mostly but trying to solve one important problem.我主要是前端,但试图解决一个重要问题。 All my backend is on java and I know you can load data to the page before it loads and then display it in html between the <%= data %> tags.我所有的后端都在 java 上,我知道你可以在页面加载之前将数据加载到页面,然后以 html 格式在 <%= data %> 标记之间显示它。 But it takes a very long time to load all the data I need.但是加载我需要的所有数据需要很长时间。

Problem问题

Is there a way to dynamically load more data to the page after it had been loaded?有没有办法在页面加载后动态加载更多数据? Or make it work on the background (some king of async, etc.)?或者让它在后台工作(一些异步之王等)?

Right now waiting time before page loads is 5-10 seconds and it is extremely long.现在页面加载前的等待时间为 5-10 秒,而且非常长。 Also, while page loads everything looks like it froze.此外,当页面加载时,一切看起来都像冻结了一样。

More info更多信息

Please let me know if you need an example of my code, etc. Thank you!如果您需要我的代码示例等,请告诉我。谢谢!

I tried researching about it but only found some suggestions to use jQuery or other languages/plugins which i did not quite understand.我尝试研究它,但只发现了一些使用 jQuery 或其他我不太了解的语言/插件的建议。 I would like to make a solution which works with only jave, JS, jQuery if possible.如果可能的话,我想做一个只适用于 jave、JS、jQuery 的解决方案。

I actually found a solution to the problem, just wondering if it is save.我实际上找到了解决问题的方法,只是想知道它是否可以保存。

I am using the following code: Jsp file which I load data to:我正在使用以下代码:我将数据加载到的 Jsp 文件:

 <c:import url="AllPendingMyDeals.jsp?<%= UserID %>" var="dataPending" />
//creating span to load data into
<span id="AllPendingMyDealsSpan"></span>

file AllPendingMyDeals.jsp:文件 AllPendingMyDeals.jsp:

//loading all libs and classes
<%@ page import="java.sql.*" ..... %>

//Calling the functions from java to load the data
ArrayList<Transaction> AllPendingMyDeals = new ArrayList<Transaction>();
AllPendingMyDeals=myRDS.GetAllPendingBrokerDeals( 1,BrokerID, BrokerID ,"0");
<html>
//creating the template for my data to be displayed (with classes and styles)
 for( Transaction Trans : AllPendingMyDeals){
<div>.....</div>
}
</html>

And the javascript function to call and load data:以及调用和加载数据的 javascript 函数:

function getDataPending(callback){
   $.get('AllPendingMyDeals.jsp', function(response) {
     // Dynamically insert the data into the page
     $('#AllPendingMyDealsSpan').html(response).ready(checkdata());
   });
 }
//function for checking loaded data after loading
 function checkdata(){...}

Now I am unsure how safe it is and am still solving a few issues with it.现在我不确定它有多安全,并且仍在用它解决一些问题。 Is it a good way to do it or Ajax is better?这是一个好方法还是 Ajax 更好?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM