Discussions

Web tier: servlets, JSP, Web frameworks: what does '?' mean in the following statement

  1. href="BookDetail.jsp?item_id=<%=java.net.URLEncoder.encode(result.getString(1))%>"

    And please also give me a hand in these question .

    1.Is '?' the default ways to pass the params along with a link to another jsp ?
    2.The params is named at the time we write that code or it is named before ? And how ?
    3. How the BookDetail.jsp receive the params to look it up in the database and show all the details of that book name out ?

    It would be very nice of you if you could give me some advices !
  2. The ? and & are the standard ways of passing parameters in HTTP.

    i.e.

    www.theurl.com?param1=value1&param2=value2

    You can collect the parameters up within a servlet with something like

    HttpRequest.getParameterValue("param1");

    Ian Purton
    Website Uptime and Availability | Permission Email List Management | Smartphone GPS | All Time Top 100 Rock Charts
  3. Ian is correct, and you should know that the questions you have asked are incredibly basic. Any half-way decent beginners book would have the answer.
    If you don't know this, you're going to be writing code that is going to just plain suck.
  4. Hilariously, I worked with someone on a project who didn't know this most basic stuff.

    In a typical JSP of his, he got the url as a string and manually parsed it to extract the parameters. And he assumed the order of the parameters was fixed! I've never seen anything like it!
  5. ? saperates URL and list of parameters. where as & saperates each parameter.
  6. BTW, This is an example of HTTP GET method. Post shouldn't have this type of list.
  7. Take a look at the following URL to understand HTTP URL submission:

    http://www.cs.tut.fi/~jkorpela/forms/methods.html