How do i reduce response time - performance

I am loading a jsp, in which there is an internal request to another server.
eg.
<html>
<head>
</head>
<body>
<div> Welcome to....</div>
.....
.....
<%
HttpConnection conn = new HttpConnection("http://someothersite/somepage");
conn.getResponse ();
%>
<div><%=response%></div>
....
</html>
what are all the better ways to reduce the response time in this case?

Try using Asynchronous Javascript(AJAX).
The response time may be the same. But it will not block the other parts of your page to get loaded. Populate the required div with the Ajax response.
You may get a lot of articles regarding how to use AJAX on a google search.

Less database connection and use optimize query.
use to cache js and picture

Related

can i define global variables for an email in eloqua

I am using eloqua for email marketing and i do not see any way to define global variables in the email. Is there any script that eloqua uses that i can use to define some global variables at the top of the email so i do not have to define values several times in the html?
I am looking to define variables like this:
var mylink = "www.google.com";
<!DOCTYPE html>
<html>
<head> </head>
<body>
Visit Website
</body>
</html>
Eloqua actively blocks java scripting in emails[1].
What you are attempting is bypassing eloqua built in functions.
Either utilize the field merge or dynamic content modules to achieve your desired outcome.
If you have a range of values, picklists can be very powerful.
1 https://docs.oracle.com/en/cloud/saas/marketing/eloqua-user/Help/Emails/HTMLemailCodeRequirements.ht

Django ajax response contains cloudflare script

I am learning Django by developing a web application. I have added the site to cloudflare CDN's free service. After a long learning curve i am able to send request to Django application using ajax, but strangely the response contains the script from cloudflare embedded as part of it.
Example ajax response:
<html><body>No arguments passed<script type="text/javascript">
//<![CDATA[
try{if (!window.CloudFlare) {var CloudFlare=[{verbose:0,p:0,byc:0,owlid:"cf",bag2:1,mirage2:0,oracle:0,paths:{cloudflare:"/cdn-cgi/nexp/dok3v=1613a3a185/"},atok:"b4c8a1a8481c9535dc367c9b4c8c52ab",petok:"e3070e55a3a1fceb44356d479cfa086f3dd56bbe-1429555139-1800",zone:"mydjango.in",rocket:"0",apps:{}}];CloudFlare.push({"apps":{"ape":"0c86dff90b5e1a63e6c69c775ca3d309"}});!function(a,b){a=document.createElement("script"),b=document.getElementsByTagName("script")[0],a.async=!0,a.src="//ajax.cloudflare.com/cdn-cgi/nexp/dok3v=7e13c32551/cloudflare.min.js",b.parentNode.insertBefore(a,b)}()}}catch(e){};
//]]>
</script>
</body></html>
The views.py code to return the response:
def send_response(request):
inpval = request.GET.get('inputval','')
if not inpval:
html = "<html><body>No arguments passed</body></html>"
else:
html = "<html><body> %s </body></html>" % inpval
return HttpResponse(html)
Can anyone help me understand how to remove this extra script from cloudflare?
Well, i figured out the issue, cloudflare is adding its own <script> tag just before </body>. So, instead of returning the result with html tags, just retrieved the values and processed them in the client.
Example:
if not inpval:
html = "No arguments passed"

using ajax to request information from MongoDB

Here's the thing. I decided to start learning Html/CSS/JS this summer and now that I already dominate Static webpages I'm trying to get over Dynamic webpages.
To learn it, I've decided to make a test website that will search (with some filters) books on a database. Since I don't need the database to be relational, I've decided to install MongoDB on my server and use AJAX to communicate with the server, but after some days reading tutorials and going further searching on google, I don't manage to get enough information to make a code that is able to read from the server.
First of all I added a simple JSON book on the database lets assume its url is something like 100.100.100.100:3000/library and the content is:
[
{
"_id":"book1",
"desc":"blablabladescription",
"cost":"15€"
}
]
and now I want to create a button on the html that calls a function to access the database. My general idea on how to do this is this:
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<title>mongoDB AJAX demo</title>
<script type='text/javascript' src='jquery-latest.min.js'></script>
<script type='text/javascript'>
function handler() {
var result;
$.ajax({
url: 'http://100.100.100.100:3000/library,
type: 'get',
dataType: 'jsonp',
jsonp: 'jsonp',
success: function (data) {
console.log('success', data);
},
error: function (XMLHttpRequest, textStatus, errorThrown) {
console.log('error', errorThrown);
}
});
return result;
}
</script>
</head>
<body>
<button type="button" onclick="handler()">click</button>
</body>
</html>
This code is a general idea I have on the structure on requesting from my server, but I know it's incomplete. I think I should make some new XMLHttpRequest(); variable.open("GET","something",true); variable.send() and also to use some callbacks to deal with async.
I hope you can help me with this doubts. I just need an explanation on how to do this or some website that has a deep tutorial, I've been using http://www.w3schools.com/ basically.
Thanks, bertri
Fortunately you can not access your database from your client-side application directly. You need to have a server-side application to access your MongoDB. Also see this post which is a near-duplicate: Client-side jQuery application with MongoDB
Based on what you feel most at home with (javascript?) the suggested choice for you would be Node.js. In Node.js you set up your connection to the database and a REST-interface to your client-application. If you want to make it really easy for yourself and just purely focus on the front-end I suggest you look into deployd.js on deployd.com. This sets up the whole back-end for you in a NoSQL database. Consequently you make ajax calls to your own API to persist, modify and retrieve objects.

Redirect to a JSP using AJAX upon completion

I am very new to AJAX and I am stuck with a problem. I have a <div> in my JSP. I have another JSP that is included in the above JSP using <jsp:include>. The problem is that the included JSP does DB operations and it takes a lot of time to render. I want the former JSP to be loaded first and then latter JSP to be rendered in the DIV. I searched but couldn't understand how to resolve it. Basically, I want the former JSP to be displayed and then the latter to be displayed once it completes operations. Currently, the former JSP takes lots of time to load as the latter is included in the former JSP and will render only when the latter JSP has completed loading.
Appreciate your help. :)
I believe this is not the correct approach . The DB interaction part should be done by the DAO classes triggered by some Servlet . Using JSP for DB interactions is bad . Having said that your current problem can be solved by the below approach :
Remove all the DB operations from the JSP.
Keep a div inside your main JSP.
On load , trigger an AJAX call to a Servlet.
Servlet/DAO class performs the DB operations and returns back the result. Store the result in session if needed.
Inside the success handler of the AJAX request function , write a call back function which loads the other JSP file.
Check this answer Load a jsp page using AJAX load method.
The popular approach is to use javascript library such as jQuery and invoke the long-running operation using ajax
$.ajax('/longrunningop', {
type: 'POST',
data: 'a=1&b=2'}).done(function(data) {
// code to display data to div here..
});
Good practice is you code the long running operation to return JSON instead of JSP

What might be causing this IllegalStateException discrepancy in JSP/Spring?

I had a JSP file with a c:redirect tag that would forward along a user to another page.
<!-- Yes, I know this loop is probably unnecessary, but I'm not fluent in jsp and have determined it is not the problem. :) -->
<c:if test="${cmd.numberOfResults == 1}">
<c:forEach items="${cmd.matches}" var="someVar">
<c:redirect url="/loadThatResultInfo.html"/>
</c:forEach>
</c:if>
The old implementation of the command object is needs updating (where I come in). The way I'm doing so is by creating a generic "search result" object which contains an instance of that old object (for now). I get that instance through a property in that generic class, so my code is now this:
<c:if test="${cmd.genericSearchObject.numberOfResults == 1}">
<c:forEach items="${cmd.genericSearchObject.matches}" var="acct">
<jsp:forward page="/loadThatResultInfo.html"/> <!-- new try! -->
<c:redirect url="/loadThatResultInfo.html"/> <!-- old try... -->
<% response.sendRedirect("/loadThatResultInfo.html"); %> <! new try! -->
</c:forEach>
</c:if>
Each of those three tries all result in IllegalStateExceptions of some sort. Why does this change cause the exception, especially considering that the lines involved -- the redirect, not the changed/bound class instances -- are causing the problem?
Back-end changes were made accordingly, referencing the property within my new encompassing "generic" class to satisfy the old functionality. I know this works because all related functionality, beside what I'm writing about, works.
Research online indicates:
- I can't redirect/forward after a submission has already been submitted. Then how was I able to do it before?
- Attempt to flush an already-cleared buffer causes this. What changed that makes it cleared now as opposed to the older (first) implementation?
- The size of the page's buffer needs to be bigger. THIS is one I don't understand and would really love for the stackoverflow community to address; I can see my new class causing size changes that would need changes to be dealt with.
------- ANOTHER ANSWER! -------
First and foremost, ALWAYS SET UP THE SITUATION IN THE CODE as described by the marked answer. However... if you're stuck and don't want to do that, here's a quick fix: javascript!
<script type="text/javascript">
location='./yourPageToGoTo.html'
</script>
JSP is part of the response. You're attempting to change the response destination in a JSP instead of in a controller. If you do this halfway in a JSP, then it's too late, because the HTTP response headers may already have been sent (the response is then in committed state). This is a point of no return and an illegal state for changing the response. It's too late then. Any attempt will result in the servletcontainer to throw IllegalStateException: response already committed.
To fix this, you need to put this piece code in the very top of JSP file and pray that the response hasn't already been committed at that point (which will usually happen after writing about 2KB of data to the response, depending on the servletcontainer config). However, JSP is still the wrong place for the job, you should rather do this in the controller, before forwarding the response to the JSP (or to instruct from within the model the controller somehow to do the job, when you're using a MVC framework).

Resources