I have an application using struts2-ognl. I have an array of strings and it gets populated by GET parameters in the request. Like the following example
http://localhost:8080/myapp/myAction.action?myArray[1]=value1&myArray[2]=value2 etc etc
Is there any way to instruct ognl that for arrays I don't want to use "[" or "]" but another set of characters ( let;s say for example "(" and ")" so the url could work like:
http://localhost:8080/myapp/myAction.action?myArray(1)=value1&myArray(2)=value2 etc etc
I'm asking this because "[" and "]" are url reserved characters. I have tried to urlEncode them but then ognl ignores those parameters.
Related
I have been using and still learning query expr(). I have a complex query where I cannot use if first to check if a parameter is '' - empty string.
I have to check it inside andX with nested orX using something like:
->andWhere($expr->orX($expr->eq(':sid', ''), $expr->neq('s.id', ':sid')))
Note: I know this line can be done by using if check first, I am using it just for an example, I got error says:
Error: Expected Literal, got ' OR '
I really need to compare empty string inside expr(), how?
Because '' is not an empty string. It's nothing and so it evaluates to nothing in DQL/SQL. Normally doctrine expects an named parameter. Either you create one to get quoted empty string or supply an empty string quoted by yourself.
Named parameter:
$qb->expr->eq('foo', ':foo');
$qb->expr->setParameter('foo', '');
quoted by yourself:
$qb->expr->eq('foo', "''");
Many languages allow one to pass an array of values through the url. I need to , for various reasons, directly construct the url by hand. How is an array of values urlencoded?
It looks like the content in the form of MIME-Type: application/x-www-form-urlencoded.
This is the default content type. Forms submitted with this content type must be encoded as follows:
Control names and values are escaped. Space characters are replaced by +, and then reserved characters are escaped as described in [RFC1738], section 2.2: Non-alphanumeric characters are replaced by %HH, a percent sign and two hexadecimal digits representing the ASCII code of the character. Line breaks are represented as "CR LF" pairs (i.e., %0D%0A).
The control names/values are listed in the order they appear in the document. The name is separated from the value by = and name/value pairs are separated from each other by &.
Which is used for the POST. To do it for the GET, you'll have to append a ? after your URL, and the rest is almost equal. In the comments, mdma states, that the URL may not contain a + for a space character. Instead use %20.
So an array of values:
http://localhost/someapp/?0=zero&1=valueone%20withspace&2=etc&3=etc
Often there is some functionality in libraries that will do the URL encoding for you (point 1). Point two is easily implementable by looping over your array, building the string, appending the index, =, the URL encoded value and when it's not the last entry an &.
Hi ive got this regular expression and that extracts numbers from a string
string.Join(null,System.Text.RegularExpressions.Regex.Split(expr, "[^\\d]"));
so eg, the format of my string is like this strA:12, strB:14, strC:15
so the regex returns 121415
how can I modify the expression to return
12,14,15 instead, any suggestions please
You're calling String.Join, which joins an array of strings into a single string, separating each element by the separator parameter.
Since you're passing null as that parameter, it doesn't put anything between the strings.
You need to pass ", " instead of null to separate each string with ,.
I need to pass '+' via the QueryString.
some special character can be passed by using 'Encode' .. but '+'
I know the one solution, If I replace '+' with other character.
But it's not the perfect solution.
[edited]
well I used escape() javascript function to encode.
escape function can't encode + . is the another function to encode on javascript?
Rather than handling on a case by case basis, with Javascript you can encode all data you pass via query string with encodeURIComponent
<script>
var data = ")(#&^$#*&^#!(!*++=";
var encodedData = encodeURIComponent(data);
alert(encodedData);
</script>
Use %2b to pass the + character.
The space character is usually passed as %20.
The same way, the plus sign can be passed as %2B
In ASCII, the hex code for + is 2B, so you should be able to just use %2B instead of +.
http://www.google.com/search?q=c%2B%2B+java
I need to pass 2 parameters in a query string but would like them to appear as a single parameter to the user. At a low level, how can I concatinate these two values and then later separate them? Both values are Base64 encoded.
?Name=abcyxz
where both abc and xyz are separate Base64 encoded strings.
why don't you just do something like this
temp = base64_encode("var1=abc&var2=yxz")
and then call
?Name=temp
Later you can decode the whole string and split the vars.
(sry for pseudo code :P)
Edit: a small quote from wikipedia
The current version of PEM (specified in RFC 1421) uses a 64-character alphabet consisting of upper- and lower-case Roman alphabet characters (A–Z, a–z), the numerals (0–9), and the "+" and "/" symbols. The "=" symbol is also used as a special suffix code. The original specification, RFC 989, additionally used the "*" symbol to delimit encoded but unencrypted data within the output stream.
You should either use some separator or store the length of the first item.
First of all, I would be curious as to why you can't just pass two parameters. But with that as a given, just choose any character that's a valid character in a URL query string, but won't show up in your base64 encoding, such as ~