Have you ever noticed some JSP incompatibilities with WebSphere? - javascript

When we write in a Javascript expression :
expression < <%=variableJsp%>
the double "<" seems to be a problem and the JSP is not interpreted ?
Is it a fault of the other servers that should not accept this type of expression ? Or WebSphere that bugs ?

Your small code-sample looks like something we do without problems.
Try creating a JSP that illustrates the problem, and nothing else. Either create a new from scratch, or remove everything not relevant to the problem.
Chances are, you will find that the error is not in your code-sample. But if you can make a small JSP-file (a few lines) that illustrates the problem, please show it to us.

I find it generally a bad idea to inline javascript on jsp pages.Your problem is only one of the reasons to make javascript functions external.
Although I do not know websphere, this has happened to me on other containers.
If you insist on keeping it inline, you can probably use
expression < <%=variableJsp%>

Related

Put JavaScript code into a string variable

I have some data wanted to be represented using datable with jQuery. As you can see, it is easy to use by including totally two, css and javascript, files. Since, as my project requirement, neither I include any file in project folder or somewhere nor I’m able to connect to the Internet, I need to escape all javascript code into a string variable then use it between <script></script> tags. To do so, I make use of the website. I think it works pretty well since its result doesn’t yield any compiler error or warning. Whenever I include it as,
<script type=\"text/javascript\" language=\"javascript\" src=\"https://cdn.datatables.net/1.10.19/js/jquery.dataTables.min.js\"></script>
it works. But when I put the content of the jquery.dataTables.min.js into a string variable by escaping via the website, I get the following error.
44th line’s the following part is hightlighted with the cross end symbol on chrome. (I’m not able to put whole code here becuase SO doesn’t permit it.)
.warn("jQuery.Deferred exception: "+e.message,e.stack,t)},E.readyException=function(e){g.setTimeout(function(){throw e})};var $=E.Deferred();function F(){v.removeEventListener("DOMContentLoaded",F),g.removeEventListener("load",F),E.ready()}E.fn.ready=function(e){return $.then(e)["catch"](function(e){E.readyException(e)}),this},E.extend({isReady:!1,readyWait:1,ready:function(e){(!0===e?--E.readyWait:E.isReady)||(E.isReady=!0)!==e&&0<--E.readyWait||$.resolveWith(v,[E])}}),E.ready.then=$.then,"complete"===v.readyState||"loading"!==v.readyState&&!v.documentElement.doScroll?g.setTimeout(E.ready):(v.addEventListener("DOMContentLoaded",F),g.addEventListener("load",F));var z=function(e,t,n,r,i,o,a){var s=0,u=e.length,l=null==n;if("object"===T(n))for(s in i=!0,n)z(e,t,s,n[s],!0,o,a);else if(void 0!==r&&(i=!0,x(r)||(a=!0),l&&(a?(t.call(e,r),t=null):(l=t,t=function(e,t,n){return l.call(E(e),n)})),t))for(;s<u;s++)t(e[s],n,a?r:r.call(e[s],s,t(e[s],n)));return i?e:l?t.call(e):u?t(e[0],n):o},_=/^-ms-/,U=/-([a-z])/g;function V(e,t){return t.toUpperCase()}function X(e){return e.replace(_,"ms-").replace(U,V)}var Q=function(e){return 1===e.nodeType||9===e.nodeType||!+e.nodeType};function Y(){this.expando=E.expando+Y.uid++}Y.uid=1,…………….. STACKOVERFLOW DOESN’T PERMIT LONG TEXT…………………..function(e,t,n){var r,i;if(e&&e.preventDefault&&e.handleObj)return r=e.handleObj,E(e.delegateTarget).off(r.namespace?r.origType+"."+r.namespace:r.origType,r.selector,r.handler),this;if("object"==typeof e){for(i in e)this.off(i,t,e[i]);return this}return!1!==t&&"function"!=typeof t||(n=t,t=void 0),!1===n&&{return g.$===E&&(g.$=xt),e&&g.jQuery===E&&(g.jQuery=bt),E},e||(g.jQuery=g.$=E),E});
What’s wrong with my idea? Cannot I apply my idea?

trim() in Symfony with APY DataGridBundle

I'm having some difficulty stripping blank spaces off the end of an input in a form that uses the APY Data Grid bundle. My suspicions are that this might not be possible without cracking the source code, but I'd love a second opinion and possibly some ideas for a workaround. Quite simply the search provides no results if an extra blank character is added to the search, so I need to trim it before it hits the query.
Typically trim works fine in twig, like so:
{{ 'foo'|trim }}
However this, which uses the above mentioned datagrid, does not
{{ filterColumn(grid, 'foo'|trim) }
I've tried to handle it in the entity (the way APY works is that it takes the item directly from the entity to the twig), but that didn't work. Digging through the vendor files to find how the code takes a filter string and convert to a query, and there does not appear to be anywhere to edit the string anywhere along the way.
I'm looking for alternate solutions, such as using javascript to trim the variable before it gets posted (it's not a huge issue regarding the problems of javascript being required; it's for an internal app, and all users here have it installed). However, this too is proving difficult. I've been attempting something like this: [updating for better code]
var oldValue = document.forms[0].querySelector('input[id$="foo__query__from"]').value;
var newValue = oldValue.trim();
document.forms[0].querySelector('input[id$="foo__query__from"]').value = newValue;
However it still seems to be having the same problem. The issue is it seems to be only possible to deal with by modifying the vendor files, which a) I'm loathe to do, and b) won't work anyway, as they don't get deployed in the same way.
Note that it is difficult to call in the actual form prior to processing; there are no typical form files (e.g. formbuilder) being used by APY. All that is available to me is {{ filterColumn(grid, 'foo') }
Solutions/suggestions would be appreciated.
After some time revisited this, and came up with a javascript solution. Using this took care of the problem, and worked globally for all forms within the application.
$('form').submit(function(){
$(this).find('input').each(function(){
$(this).val($.trim($(this).val()));
});
});

Converting text to javascript and executing it

I have got formatted text(which is a piece of code) in my textarea which is beautified using the codemirror.
Now when I press the button under the textaera,I need to pass a response as a variable to the above code and execute it as javascript and obtain the result.
basically I just want something similar to jsfiddle.
How can I do this using javascript/jquery?. Is there any plugins that I could use for the same?
I think you are looking for eval function in JavaScript. I do not understand what exactly you need to achieve, but this might help:
http://www.w3schools.com/jsref/jsref_eval.asp
However, as I understand you should try to avoid eval in the code, but if this is the only way, let it be.
You can run the code in an iframe on a different domain with eval function, this causes the browser to not allow the code in the iframe access to the parent page due to the Same Origin Policy.
Well known tools created to run third-party code is Google Caja and ADsafe.

is it possible to obfuscate while using soma.js dependency injection?

While looking at how to make JavaScript source code more secure I came upon a lot of 'solutions'. but most people said the same thing; "It's not possible to make your source code 100% secure", "try obfuscation", "run your code server side", etc, etc. After reading a lot posts here on stackoverflow, and other sites I came to the conclusion that a combination of minifying and obfuscating would do the job (for me).
But here is the problem: we are currently using soma.js with dependency injection, and the way we set it up it does not work well with obfuscation. It's basically this:
var session = function(id, sessionModel){
this._sessionmodel = sessionModel;
}
mapping:
injector.mapClass("sessionModel", project.SessionModel, true);
Obfuscation will then rename the sessionModel in the function to for example 'A', but the mapping that was done on SessionModel by the injector still remains 'sessionModel' and not 'A', this then basically breaks the code.
I've read this post which is about the same subject Dependency Injection and Code Obfuscation, but it does not provide a real answer to my problem so I decided to write my own question.
Any tips/hint/suggestions are welcome.
Thanks in advance.
EDIT
It seems you can tell Yuicompressor to exclude certain identifiers by putting in 'hints' into the files like this: "identifier:nomunge, identifier2:nomunge".
var session = function(id, sessionModel){
"sessionModel:nomunge";
this._sessionmodel = sessionModel;
}
I tested this and it works but that means you'll have to put it in yourself which is a lot of work if you have to do that for every script, especially if you have a very big project..
Gonna look into it further, and update this post if anything new pops up
EDIT 2
It's been a while, I only work 1 day a week on this =S.
As said before you can get it working by telling it which identifiers to exclude.
For that I looked into regular expression to get the "mapped classes" programmatically, since doing it by hand is just insane.
What I basically did was instead of putting every hint in by hand, I made a identifier, for example "#nomunge"; and used a simple replaceregexp task to find it and replace it with a string containing all the identifiers. This string is build by loading the script and going through it with a tokenfilter.
<target name="build hints">
<loadfile property="hints" srcFile="${temp.loc}/all.js">
<filterchain>
<tokenfilter delimoutput=":nomunge,">
<ignoreblank/>
<containsregex pattern="${regexp}"/>
</tokenfilter>
</filterchain>
</loadfile>
<echo message="${hints}"/>
</target>
<replaceregexp file="${temp.loc}/all.js"
match="#nomunge"
flags = "g"
replace = "target:nomunge, dispatcher:nomunge, injector:nomunge,${hints}"
/>
This seems to do the job, for now...
I'm behind the soma.js framework, feel free to ask me questions on the google group, happy to help.
This might help a bit more:
https://groups.google.com/forum/#!topic/somajs/noOX2R4K58g
Romu

what does '</' mean in JavaScript?

I use Aptana Studio to code JavaScript.
When I write string with </, there will be warning saying
'<' + '/' + letter not allowed here
But it does not trigger error in browsers.
what does </ mean in JavaScript?
For inline scripts (e.g, using <script>), some HTML parsers may interpret anything that looks like </this (especially </script>) as an HTML tag, rather than part of your source code. Your IDE is trying to keep you from typing this by mistake.
This means that, if you're using an inline script, you can't have a </tag> as a constant string in JavaScript:
var endTag = "</tag>"; // don't do this!
You'll need to break it up somehow to keep it from being interpreted as a tag:
var endTag = "<" + "/tag>";
Note that this only applies to inline scripts. Standalone scripts (e.g, a .js file) can have anything they want in them.
It doesn't mean anything in a string, outside of a string it would be a syntax error.
EDIT: Before someone nitpicks there are some exceptions, eg var i = 1 </* comment */ 2; is legal and there may be some other cases (like performing less-than operation on a regex) but generally speaking it signifies nothing by itself.
It sounds like it's your IDE is denying it. Aptana Studio may be assuming some sort of injection attack, and thus throws an error.
You would probably get a more direct answer by asking them directly though; a general program help site like StackOverflow is less likely to know the reasoning for specific cases such as this.

Categories