Skip to main content

When LinkedIn met JSTL

Posted by felipeal on March 26, 2004 at 8:09 PM PST

JSTL's SQL and XML are controversial taglibs. A lot of people complain they hurt the MVC principles, while others defend they can be useful in some situations (specially on protoypes and small projects). The truth is, both sides are right: it can causes great havoc in a MVC-based application, but it is an invaluable tool in small, time-limited projects like the one shown below



Now let's forget JSTL for a while and talk about LinkedIn, which is the motivation for this blog entry. For those who don't know it yet, LinkedIn is a tool/site for social networking management. I joined the site a couple of months ago, invited by an old college friend. Although I was skeptical about the technology in the beginning, I slowly realized it was a nice way to keep in touch with old friends - or even strengthen my relationship with new ones.



My favorite way of using LinkedIn is browsing throughout my connections' connections looking for known folks. Once I found one, I invite him to be a direction connection of mine. There are 2 ways to ask for a connection: sending a request indirectly through LinkedIn or directly by email.



Sending a request is LinkedIn's core business. It would allow you, for instance, to propose a business deal to some one you don't personally know (but is indirectly "linked" with you through your connections) and LinkedIn would charge for the service. Although I think its a nice feature and a clever business plan, it is an overkill process if you just want to get a connection with someone you already know. So, in this case, it's much simpler to just send an email message to that person. The only drawback in this approach is that many times you don't know (or don't remember) that person's email address - and that's where my JSTL-based project can be handy.



The project's goal is pretty simple and straightforward: provide a repository of names and email address of LinkedIn users that know each other somehow (for instance, my Alumni class or java.net community users). Once a name is listed, you can just click on its email address and you will be redirected to LinkedIn's invitation page (with all fields already filled). (ERRATA: this part is highlighted because it has been missing from the original blog)



Considering the project's level of importance (it could be classified as "useless geek tools"), it has to be easy to use and even easier to implement (in fact, I spent more time configuring MySQL and writing this blog than developing the project). In other words, it's a typical example of application that could be written using JSTL's Core and SQL tags.



The application consists of only 2 database tables (users and communities) and 3 JSP pages:

  • index.jsp - protected page (user must login before accessing it), allows an user to add himself to the community or send an invitation to other users
  • login.jsp - welcome page where the user selects with community he would like to access (it's necessary to know the community's password)
  • listUsers.jsp - list all users in a community, with a link for posting a LinkedIn invitation to each user (this page is included from index.jsp



Here are some code snippets (the whole "source" can be found here):




<%-- check if user is logged on --%>


  


<%-- check if user already exists in this community --%>
       
           SELECT * FROM users WHERE email = ? AND community_id = ?
          
          
       

       
          
       


<%-- handle submission --%>

  
  
  
     
        
     


     
       
           SELECT * FROM communities WHERE id = ? AND password = ?
          
          
       

       
          
       

       
          
          
          
          
       

       
     

  







Finally, the application URL is http://felipeal.net/liar/index.jsp. If you had the patience to read this lengthy blog till this point, please give it a try - the password for java.net is CafeBabe.

Related Topics >>