access using URL:
http://127.0.0.1/test.jsp?action=test&abc
or
http://127.0.0.1/test.jsp?abc
how can I get the String "abc" ?
thanks for help :)
<% java.util.Enumeration names = request.getParameterNames();
while(names.hasMoreElements()){
out.println(names.nextElement() + "<br>");
}
%>
I don't think there is a simple way to do this. Basically you need to iterate over the request's query parameter names and look for the parameter or parameters that don't have a value. I suspect that you will need to resort to embedding a Java scriptlet, or writing your own Tag (in Java).
A better idea is to stick to "name=value" syntax in your URL query.
request.getQueryString();
returns the whole query string after the URL.
Related
Say I have the URL:
http://185.112.249.77:9999/Api/Search?search=#9QLU9CY8
And then code:
String search = request.getParameter("search");
Then search is blank...
I need a way to get around this. The url is visited directly. Is there something I can do in Tomcat's config to make this work?
I tried replacing "#" with "%23" with a search.replace but that also didn't work.
Thanks!
That's because the '#' character is not part of the parameter but is a fragment identifier. So your parameter is actually empty
see this link to get more info about url params structure
[https://www.rfc-editor.org/rfc/rfc3986#section-3.5]
Or
[https://www.rfc-editor.org/rfc/rfc3986#appendix-A]
For the formal definition
192.168.178.83:18300/Zupdate_we_view.act?name=bunnavitou&position=Research111&sex=Male
hide value on url
from this one :
192.168.178.83:18300/Zupdate_we_view.act?name=bunnavitou&position=Research111&sex=Male
==>To this :
192.168.178.83:18300/Zupdate_we_view.act?
Need Help !! JAVA or JAVA SCRIPT
The best way to hide values on url is to use POST method.
Click HTTP Methods: GET vs. POST or GET vs POST
for more info about GET and POST methods.
First you have to get the url, modify it, and then with javascript replace the "true" url with the one you just modified. Here is what I would do:
//get the url
$old_url = "http://".$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'];
//then you modify it
$new_url = ...;
//then with javascript you replace the url with the new one
<script type="text/javascript">
if(new_url != '')
{
window.history.replaceState({"html":'Title',"pageTitle":'Page Title'}, '', new_url);
}
</script>
This should do the trick, if you really want to use GET ; POST would be better, and you wouldn't have to hide the GET parameters.
Like others suggested, use POST method, but if you want to stick with GET and JavaScript solution is enough (values can be seen in request same as with POST, but furthermore users with disabled JS will see the values), you can use approach described here: https://developer.mozilla.org/en-US/docs/Web/Guide/API/DOM/Manipulating_the_browser_history
Another way is to encode the values on first page & pass those values and decode the value
on second page.
Using that technique you have no need to post data. User can also read the parameter but
it is encoded not the real value.
You can use different algorithm to encode/decode parameter on both side.
How can i pass argument through url in jquery?
I had my code like this
getCIVectorsFormObj.action='getParentChildCIVectors';
to this action, i want to add argument
customerID
like
getParentChildCIVectors.java?customerID=customerID
please help me out..
I am struck
Thanks in advance
You can use page Name and add query param like this. getParentChildCIVectors.jsp?customerID=customerID
You have to append the arguments as regular Strings:
getCIVectorsFormObj.action='getParentChildCIVectors.java?customerID'+customerID;
Simple it is just string concatenation declare one variable url as
var url = 'getParentChildCIVectors'; //this is your action
Now, adding argument is done by
url += '?customerID='+customerID;
And at last set the action to form as
getCIVectorsFormObj.action = url;
Edit
Passing more parameters then just concatenate
url +='customerName='+customerName;
.......
..........
I am trying to send the following parameters to a server through HTTP POST:
["my_session_id","{this=that, foo=bar}"]
But the server is returning a parse error because of the quotes around the hash.
I am trying to remove them with a regex like so:
params.replaceAll("\\\"\\{", "\\{");
params.replaceAll("\\\"\\}", "\\}");
In all honestly I have no idea what I'm doing. Please help.
Thanks in advance!
There's two issues here: First, you're not re-assigning the string. Strings are immutable in Java (cannot be changed), so you must assign the result. Second, you're replacing "} instead of }".
Here's what I used:
String params = "[\"my_session_id\",\"{this=that, foo=bar}\"]";
params = params.replaceAll("\\\"\\{", "\\{");
params = params.replaceAll("\\}\\\"", "\\}");
System.out.println(params);
Which prints out:
["my_session_id",{this=that, foo=bar}]
PS: Bit of advice, use JSON. Android has excellent JSON handling, and it is supported in PHP as well.
Is there a reason you are using the regular expression replaceAll? Alternatively, you might try:
String parameters = parameters.replace("{", "\\{").replace("}", "\\}");
I am trying to get the request parameter which has '&' sybol in starting like:-
http://localhost:8080/simple.jsp?my=&234587
On other page I'm getting it like String value=request.getParameter("my");
value.substring(0,4);
I want to get &234, please suggest i am not getting any value.
Thanks,
Ars
In this example you have not one, but two parameters:
my
234
234 is not a value here. The & separates query parameters. If you need that ampersand to be part of the value of my, it needs to be escaped in the URL as %26.
thanks for resonse i found the answer, I used request.getQueryString(); to get the whole string i.e. &234587 and then parsed it accordingly.
:)
Thanks once again.
You will most likely have to encode the '&' in the url:
http://localhost:8080/simple.jsp?my=%26234587
If you will be handling only Get request. You can write something like this.
String requestURI=request.getRequestURI();
String pContent=requestURI.split("?")[1];
String[] pArray= pContent.split("&");
String value="";
for (int i=0 ;i<pArray.length;i++) {
if(pArray[i].equals("my"+"=")){
value="&" + pArray[i+1];
break;
}
}