Sponsered Links
Categories
Sponsered Links

Token Servlet Example

 

This example illustrates how to generate random token number bu using servlet.

import java.io.*;
import java.util.Random;
import javax.servlet.http.*;
import javax.servlet.ServletException;

public class TokenServlet extends HttpServlet {
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        String tokensID = request.getParameter("tokenID");
        response.setContentType("text/html");
        PrintWriter pw = response.getWriter();
        pw.println("<html><head><title>Tokens</title></head><body ");
        pw.println("style=\"fonr-family:verdana;font-size:10pt\">");
        if(tokensID==null) {
            Random rnd = new Random();
            tokensID = Long.toString(rnd.nextLong());
            pw.println("<p>Welcome. A new token " + tokensID + " is now established</p>");
        } else {
            pw.println("Welcome back.. Your token is " + tokensID + ".</p>");
        }
        String requestURLSame = request.getRequestURL().toString()+"?tokens=" +tokensID;
        String requestURLNew = request.getRequestURL().toString();
        pw.println("<p>Click <a href=" + requestURLSame +" > here </a> again to continue browsing with the "+ " same identify. </p>");
        pw.println("<p>Otherwise, click <a href = " + requestURLNew + "> here</a> again to start browsing with a new identify. </p>");
        pw.println("</body></html>");
        pw.close();
    }
}

 
 
Sponsered Links
Latest Updates
 
All Content of this site is for learning only. We do not warrant the correctness of its content. The risk from using it lies entirely with the user. While using this site, you agree to have read and accepted our terms of use and privacy policy.
Copyright © 2009 JSPSERVLETTUTORIAL.INFO All Right Reserved