In PHP all the GET parameters and values can all be easily accessed through $_GET. How about in Java, is there any way to do the same as that? Probably by using JsonObject class.
I hope you guys can help.
In PHP all the GET parameters and values can all be easily accessed through $_GET. How about in Java, is there any way to do the same as that? Probably by using JsonObject class.
I hope you guys can help.
 
    
    In PHP all the GET parameters and values can all be easily accessed through $_GET.
In Java, more specifically in plain Java EE, you will use a Servlet to process the requests in server side, never do it directly in your JSP by using scriptlets, avoid its usage. In your servlet, you will have a doGet method that receives a HttpServletRequest parameter that gives you access to all the request parameters (including the query string parameters) by usage of getParameter method. Here's a small sample:
@WebServlet("/hello")
public class HelloServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        //retrieving the query string parameter "name"
        //this will work if you access to http://your.host.url/app/hello?name=foo
        String nameQueryStringParameterValue = request.getParameter("name");
        //will print "foo" (or the query string parameter value) if the url contains it
        //otherwise, it will print null
        //this will be printed in console output
        //Note: in real world apps, you should use a logger instead of sysout
        System.out.println(nameQueryStringParameterValue);
        //continue your request processing logic...
    }
}
In case you don't want/need to manually ask for every request parameter, you may use a web MVC framework that helps you handling this. For example, JSF <f:viewParam> as shown here: What can <f:metadata>, <f:viewParam> and <f:viewAction> be used for?.
Note that this has nothing to do with retrieving the request parameters as a Json Object.
 
    
    