如何在JSP中执行Java代码后才显示页面 [英] How to show page only after executing Java codes in JSP

查看:162
本文介绍了如何在JSP中执行Java代码后才显示页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

index.jsp 包含Java代码,可从数据库中获取一些图像和文本。



我写的JavaScript文件。

  $(document).ready(function(){
//当Document是Ready,显示主页
$(#showifjavaenabled)。fadeIn(1000);

});

所以在开始时, DIV showifjavaenabled 是隐藏的,但我注意到,即使它在1秒后显示,并不是所有的java都被执行,因为它们实际上是很多的,它们需要加载的时间并不是很大,它只有一两秒钟,但它仍然在寻找不好,我只能在所有的java代码执行后才能 .show()或.fadeIn()这个页面

这是不将java代码放入JSP中的原因之一...
$ b

如果您正在执行基于服务器的操作,或者你可以使用AJAX调用来执行Java前端操作,或者你可以使用AJAX调用来执行Java前端操作,使用类型的瓷砖(页面被加载,使用ajax加载的小盒子仍然继续运行,直到完成为止。



避免scriptlets( <%%> )尽可能多,并分开浓缩epts获得更好的结果。




编辑:
您应该尝试从Struts2之类的框架开始不是Struts1,这是更难和更强大)。



这并不困难,记录良好,您花时间学习'hello world'并设置应用程序的时间将立即以力量和易用性的方式回归,您可以将它用于将来的应用程序。



将一个巨大的逗号分隔的字符串从服务器发布到客户端,然后对其进行去标记化,但没有面向对象的编程。对于每个需要使用的概念对象,通过Action暴露给JSP并在JSP中使用EL或OGNL标记进行访问时,OOP将成为一个对象。 p>

我知道这一步看起来很大,但值得这样做......



或者你可以留下你的反模式,先前的技术和尝试破解这个问题,也许今天你会结束这个软件,但明天你也会遇到同样的问题。

我的2美分(如上所述,我几年前就在你的情况......)

The index.jsp contains java codes which will fetch some images and texts from a database.

In the JavaScript file I wrote.

$(document).ready(function(){
    //When Document is Ready, Show the Main Page
    $("#showifjavaenabled").fadeIn(1000);

    });

So in the beginning, the DIV showifjavaenabled is hidden, but I noticed that even when it shows up after 1 second, not all java are executed because they are actually a lot, the time they need to load isn't big, it's only a second or two, but still it's looking bad, how can I .show() or .fadeIn() this page only after all java codes have been executed?

解决方案

This is one of the reasons for not putting java code into JSPs...

If you are doing server-side business, you should do it server side, then forward the request to the JSP with all data already loaded.

OR you can use AJAX calls to perform Java frontend operations, using kind of tiles (the page is loaded, the little box loading with ajax has still the progress bar running until he's done.

Avoid scriptlets (<% %>) as much as you can, and separate concepts for a better results.


EDIT: You should really try to start with some framework like Struts2 (not Struts1, that is harder and less powerful).

It's not difficult, well documented, and the time you spend to learn the 'hello world' and to setup your application will come back immediately in terms of power and easyness, and you could use it for future applications.

Posting a gigantic comma separated string from server to client, and then de-tokenize it there is not Object Oriented Programming.

OOP would be one object for every conceptual object you need to work with, exposed to the JSP through an Action, and accessed in JSP with EL or OGNL tags...

i know the step seems huge, but it is worth doing...

Or you can stay with your antipattern, antediluvian technology and try to hack this problem, maybe for today you will end this software, but tomorrow you will have the same problems.

My 2 cents (as said, i was in your situation years ago... )

这篇关于如何在JSP中执行Java代码后才显示页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆