简体   繁体   中英

URL Parameters and AJAX Problem

I have a JSP page that when loaded calls a JavaScript function (loadData()), this function uses an AJAX request to retrieve data from a servlet and return the necessary HTML content to the page.

I want to call this url from a button and pass a URL Parameter (....jsp?name=joe), I can do this, but when I try to retrieve it from the servlet I can only see the parameters passed in the AJAX Request, not the parameter in the URL...

Is there a reason this is happening? Should I go about this a different way?

Thank you!

It sounds like as if the Ajax request is actually a HTTP POST request. This way the GET query string in URL will indeed not be parsed. You need to parse it yourself in the doPost() method of the servlet. It's available by HttpServletRequest#getQueryString() .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM