title: how to make a Facebook application in java using eclipse and jboss?
body: <p>I am trying to develop a facebook application using java. Can anyone please help me out?</p>
  
  <p>I have used the code provided in <a href="http://www.developer.com/java/article.php/10922_3733751_7/Writing-Facebook-Applications-Using-Java-EE.htm" rel="nofollow">http://www.developer.com/java/article.php/10922_3733751_7/Writing-Facebook-Applications-Using-Java-EE.htm</a></p>
  
  <p>Here I am giving two servlets and one jsp file and 1 xml file all that I got from the above mentioned site.</p>
  
  <p><strong>AbstractFacebookServlet</strong></p>
  
  <pre><code>public class AbstractFacebookServlet extends javax.servlet.http.HttpServlet
          implements javax.servlet.Servlet {
      protected static final String FB_APP_URL = "http://apps.facebook.com/myfacebookapp/";
  
      protected static final String FB_APP_ADD_URL = "http://www.facebook.com/add.php?api_key=";
  
      protected static final String FB_API_KEY = "FB_API_KEY";
  
      private static final String FB_SECRET_KEY = "FB_SECRET_KEY";
  
      public AbstractFacebookServlet() {
          super();
      }
  
      /*
       * This method is used by all of the application's servlets (or web
       * framework actions) to authenticate the app with Facebook.
       */
      protected FacebookRestClient getAuthenticatedFacebookClient(
              HttpServletRequest request, HttpServletResponse response) {
          Facebook fb = new Facebook(request, response, FB_API_KEY, FB_SECRET_KEY);
  
          String next = request.getServletPath().substring(1);
  
          if (fb.requireLogin(next))
              return null;
  
          return fb.getFacebookRestClient();
      }
  }
  </code></pre>
  
  <hr>
  
  <p>And here is the second servlet file</p>
  
  <p><strong>MainPageServlet.java</strong></p>
  
  <pre><code>public class MainPageServlet extends AbstractFacebookServlet implements
          javax.servlet.Servlet {
      protected void doGet(HttpServletRequest request,
              HttpServletResponse response) throws ServletException, IOException {
          FacebookRestClient facebook = getAuthenticatedFacebookClient(request,
                  response);
  
          if (facebook != null) {
              if (getFacebookInfo(request, facebook)) {
                  request.getRequestDispatcher("/main_page.jsp").forward(request,
                          response);
              }
          }
      }
  
      protected void doPost(HttpServletRequest request,
              HttpServletResponse response) throws ServletException, IOException {
          doGet(request, response);
      }
  
      /*
       * This method obtains some basic Facebook profile information from the
       * logged in user who is accessing our application in the current HTTP
       * request.
       */
      private boolean getFacebookInfo(HttpServletRequest request,
              FacebookRestClient facebook) {
          try {
  
              long userID = facebook.users_getLoggedInUser();
              Collection&lt;Long&gt; users = new ArrayList&lt;Long&gt;();
              users.add(userID);
  
              EnumSet&lt;ProfileField&gt; fields = EnumSet.of(
                      com.facebook.api.ProfileField.NAME,
                      com.facebook.api.ProfileField.PIC);
  
              Document d = facebook.users_getInfo(users, fields);
              String name = d.getElementsByTagName("name").item(0)
                      .getTextContent();
              String picture = d.getElementsByTagName("pic").item(0)
                      .getTextContent();
  
              request.setAttribute("uid", userID);
              request.setAttribute("profile_name", name);
              request.setAttribute("profile_picture_url", picture);
  
          } catch (FacebookException e) {
  
              HttpSession session = request.getSession();
              session.setAttribute("facebookSession", null);
              return false;
  
          } catch (IOException e) {
  
              e.printStackTrace();
              return false;
          }
          return true;
      }
  }
  </code></pre>
  
  <hr>
  
  <p>this is the jsp file</p>
  
  <p><strong>main_page.jsp</strong></p>
  
  <pre><code>&lt;%@ page language="java"
     contentType="text/html; charset=UTF-8"
     pageEncoding="UTF-8"
  %&gt;
  &lt;strong&gt;myacebookapp Main Page&lt;/strong&gt;
  
  &lt;div&gt;
        &lt;a href="http://www.facebook.com/profile.php?id=${uid}"&gt;
        &lt;img src="${profile_picture_url}"&gt;&lt;br&gt;
     &lt;/a&gt;
     &lt;a href="http://www.facebook.com/profile.php?id=${uid}"&gt;
        ${profile_name}&lt;/a&gt;,
     you are special because you are using myfacebookapp!
  &lt;/div&gt;
  </code></pre>
  
  <hr>
  
  <p>There is also mentioned that we can also replace the jsp file with the fbml file mentioned below</p>
  
  <pre><code>&lt;%@ page language="java"
     contentType="text/html; charset=UTF-8"
     pageEncoding="UTF-8"
  %&gt;
  &lt;strong&gt;myacebookapp Main Page&lt;/strong&gt;
  
  &lt;div&gt;
     &lt;fb:profile-pic uid="loggedinuser"
                     size="small"
                     linked="true" /&gt;&lt;br&gt;
     &lt;fb:name uid="loggedinuser"
              useyou="false"
              linked="true"
              capitalize="true" /&gt;,
     you are special because you are using myfacebookapp!
  &lt;/div&gt;
  </code></pre>
  
  <hr>
  
  <p>and the web.xml file is</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" id="WebApp_ID" version="3.0"&gt;
    &lt;display-name&gt;myfacebookapp&lt;/display-name&gt;
    &lt;welcome-file-list&gt;
      &lt;welcome-file&gt;index.html&lt;/welcome-file&gt;
      &lt;welcome-file&gt;index.htm&lt;/welcome-file&gt;
      &lt;welcome-file&gt;index.jsp&lt;/welcome-file&gt;
      &lt;welcome-file&gt;default.html&lt;/welcome-file&gt;
      &lt;welcome-file&gt;default.htm&lt;/welcome-file&gt;
      &lt;welcome-file&gt;default.jsp&lt;/welcome-file&gt;
    &lt;/welcome-file-list&gt;
  &lt;/web-app&gt;
  </code></pre>
  
  <hr>
  
  <p>Now, what my problem is, When I am accessing the url  <a href="http://http://localhost:8080/myfacebookapps/main_page.jsp/" rel="nofollow">http://http://localhost:8080/myfacebookapps/main_page.jsp/</a>, it is giving a 404 error.</p>
  
  <p>Can anyone please help me out what I am doing wrong? Actually I am new in this thing.</p>