开发者

How Would I Do This in Java? (A blog with some java callbacks)

开发者 https://www.devze.com 2023-01-30 18:57 出处:网络
I want to build a website that is basically a blog with a little bit of custom java code to be run via ajax calls on the server.

I want to build a website that is basically a blog with a little bit of custom java code to be run via ajax calls on the server.

My initial thoughts were to build the blog in wordpress or drupal or something similar, then run a very simple java webapp to receive the ajax requests. However, having no experience with Java webapps, I a开发者_开发百科m not sure of a framework made for such simple tasks. Nor have I ever used wordpress/drupal/etc to know how easy it would be to integrate these java ajax calls.

Then I thought, perhaps I should just run some Java CMS instead of drupal, wordpress, etc. This should allow me to easily integrate my ajax hooks. But again, I have no experience with any Java CMS's to know which would work well.

Can someone with some Java webapp experience give their recommendation?


Second time in two posts I have made the same recommendation (!) but maybe look at the free Community edition of Liferay portal server? It runs on Java (easy on tomcat+mysql) and has blogs and CMS and other features included. There is also the option of modifying the source code (subject to the license) to add your custom behaviour.


What exactly are you looking to do in Java that you couldn't accomplish in PHP if you were to use Wordpress or Drupal?

Wordpress is rather easy to setup. If you have any web app experience at all and minor knowledge of PHP then you shouldn't have any problems.

Spring MVC is a fairly straightforward Java web app framework. You can run it on Google App Engine with relative ease and there's a lot of documentation / support online.

One thing to consider is that your AJAX calls will need to be made to the same domain that your CMS is on. If you're creating two separate web apps then they need to appear to be on the same domain.

It's a bit difficult to give any detailed advice not knowing what your particular requirements are but I hope this helped a little.


I think you shouldn't use any framework. Just create a servlet. Because even if you use a framework, you still have to understand what a servlet is. These code are from oracle's site, modify doGet to do your processing. Or you could change it to doPost.

    import java.io.*;

// Packages for Servlets
import javax.servlet.*;
import javax.servlet.http.*;


public class HelloWorld extends HttpServlet {

  /**
  * Initializes the servlet. The method is called once, automatically, by the
  * Java Web Server when it loads the servlet. The init() method should save
  * ServletConfig object so that it can be returned by the getServletConfig()
  * method.
  */
  public void init(ServletConfig config) throws ServletException {

    super.init(config);
  }

  /**
  * Method to process HTTP GET requests. In this method a Simple HTML page
  * displaying "Hello Oracle World" is built and presented to user.
  * The parameters of doGet() method is
  * 1) HttpServletRequest object, which encapsulates the data from the client
  * 2) HttpServletResponse object, which encapsulates the response to the client
  **/

  public void doGet(HttpServletRequest p_req, HttpServletResponse p_res)
                                        throws ServletException, IOException {

    // Sets the content type of the response
    p_res.setContentType("text/html");

    // Create a ServletOutputStream to write the output
    ServletOutputStream l_out = p_res.getOutputStream();

    // Use ServletOutputStream to print the Hello Oracle World String in
    // the HTML page

    l_out.println("<HTML><HEAD><TITLE>Hello Oracle World</TITLE></HEAD>");
    l_out.println("<BODY BGCOLOR =\"lightgrey\"><CENTER><BR><BR>");
    l_out.println("<TABLE BORDER=4 BGCOLOR =\"blue\">");
    l_out.println("<TR><TD align =\"center\" valign=\"center\" >");
    l_out.println("<FONT face=\"Arial,helvetica\" color =red size=5>");
    l_out.println("&nbsp; Hello Oracle World &nbsp;</FONT></TD></TR></TABLE>");
    l_out.println("</BODY></HTML>");

    l_out.close(); // Close the ServletOutputStream
  }

  /**

  * Override the getServletInfo() method which is supposed to return information
  * about the Servlet, e.g. the servlet name, version, author and copyright
  * notice. This is not required for the function of the HelloWorld servlet but
  * can provide valuable information to the user of a servlet who sees the
  * returned text in the administration tool of the Web Server.
  **/
  public String getServletInfo() {
    return "Hello World servlet 1.0 by Reghu";
  }

  public void destroy() {
     super.destroy();
  }
}
0

精彩评论

暂无评论...
验证码 换一张
取 消