0

I am working on an email validation link for a website. When a user registers and finishes filling in their personal data (and it passes all the checks), they are sent to a jsp page saying that an email has been sent to the address they entered as the username, with a link to click to validate the email address. So that part is all well and good, I generate the link (for now just using my localhost) and it looks like this as an example http://localhost:9999/javawork/msc/validate/?6FRQ8RAT&u=1s3w1Iih64egX01188HT. When they click the link it goes to the jsp page index.jsp in the validation folder. At this point I need to grab the entire URL and send it to a function to make sure the URL is formatted properly (for security purposes). If it passes and the format is fine, I need to grab the 8 digit code immediately after the '?' and also the value of 'u'. I then send those values to a function that checks that they match what we have in our DB, and if they do, I update the DB record with a validation date so we know they have validated their email address.

So my question is first, how do I grab the entire URL to check the format, and second, how do I grab the 8 digit code, and the value of 'u'? I have been looking online and all examples require creating multiple functions or classes, and using the URL class. And they all want me to make an instance of a URL object and initialize it using the entire URL. But it is not a static URL, it will be different for every user that registers, as it generates a random 8 digit code to check against, and the value of 'u' is the masked user id from the DB. I don't understand how it can require you to initialize the entire URL in order to get the values, when you don't know what the values are until you get them from the URL.

Is there a simple way to grab the values, and the entire URL? Even if I can just get everything after the '?', I know the base URL and can build a new String to check the formatting if I can get from the '?' and after. Please help with that part. Thanks.

2
  • Are you writing a servlet to process the request from the client or simply a .jsp page?
    – D.Shawley
    Jul 27, 2012 at 15:34
  • just a jsp page. I already have functions in a java class to check the values against the DB. I just need the jsp page to grab the URL values, pass them to the functions (which return a boolean) and then the jsp page displays a success message if true is returned and a failure message if false is returned.
    – kei23th
    Jul 27, 2012 at 15:35

2 Answers 2

1

The Interface HTTPServletRequest contains a method getRequestURL which returns a StringBuffer which you may use to check the format of the entire URL. You can get it, in a jsp page with :

<%=request.getRequestURL()%>

If you are using the format of request that you specified above, then your second question :

how do I grab the 8 digit code, and the value of 'u'?

May be answered by manipulating that StringBuffer to split at the ? and & for the 8 digit code. Or use another request method, ServletRequest.getParameter(java.lang.String name)

To grab each parameters, though, i'm not certain how it will end up handling the unnamed parameter of the 8 digit code. Let me know how that goes.

3
  • that is exactly what I needed. Once I have the entire URL I can split it at the '?' like you said. Thanks so much.
    – kei23th
    Jul 27, 2012 at 16:35
  • 1
    <%=request.getRequestURL()%> only gives me up to the '?' but not the '?' or anythnig after. Any idea how to grab the query string parameters also?
    – kei23th
    Jul 27, 2012 at 17:31
  • You make an excellent point, my mistake. The second method that I provided will do the trick. request.getParameterNames() will return an Enummeration of the paramter names, which you can use along with request.getParameter(java.lang.String name) to step through each parameter and get its value.
    – OYRM
    Jul 27, 2012 at 17:52
0

Don't think of the 8-digit code as an unnamed parameter. Think of it as a parameter without a value.

request.getParameterNames() will give you the 8-digit code as well as "u". So you can loop through like so: String code = "";

for(String paramName : request.getParameterNames()) {
    if(!paramName.equalsIgnoreCase("u"))
        code = paramName;
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.