Jfinal Study Notes (i) jfinal environment configuration under Tomcat

Source: Internet
Author: User

Recently I was going to make a personal website that belonged to me and was going to use Microsoft. NET to develop, but listening to a friend said that there is a Java-based open source framework jfinal and. NET development model is very similar, but also has the advantages of. NET rapid development and Java security. Out of curiosity I intend to study the jfinal framework to see if it is really so divine.

At the same time I will learn every important step of my study or encountered in the blog detailed records, mainly for their own study notes, to prevent a period of time will not be forgotten later. Say I did not write the habit of blogging before, often happened before some development technology after a period of time not to use the oolong, resentment ah. Of course it would be nice if my notes could help someone else.

Enter the topic below. The first problem I encountered when learning the Jfinal framework was the configuration of the environment. The help document given by Jfinal is debugged using the jetty program. But this jetty I have never used, I am afraid that in the following development will have unnecessary trouble, so I decided to debug the Jfinal project under Tomcat, in fact, the configuration process is not complicated, and the configuration method in the Help document is roughly the same.

Before you make the environment configuration, first make sure that Eclipse and Tomcat are installed (as if it's nonsense, of course), and the version is as high as possible, because Jfinal is the 2011 framework, and the version is too low to know if there is a problem. I'm using Eclipse Juno and Tomcat 7.0.

With Eclipse and Tomcat in the first place to bind Tomcat in eclipse, I forget how to bind each time, so here's a little bit of a talk about Tomcat's binding method.

First, in Eclipse, click Window-->preferences in the menu bar and select Sever-->runtime environment in the left column of the popup dialog box.

Configuring Tomcat for the first time there should be no option on the right, I have a Tomcat 7.0 running environment because it is now well-equipped. First configuration Click the Add button directly.

In the pop-up dialog box, select the version of Tomcat you are installing now, and mine is 7.0 so choose the 7.0 version and click on the Next button.

Enter the installation path for Tomcat in the installation path, typically the default path is C:\Program Files\apache software foundation\tomcat 7.0, click Finish to complete the tomcat binding.

Following the creation of a project, you first create a Dynamic Web project in Eclipse.

Click Next to fill in the basic information of the project.

Note that the target runtime here is different from the jfinal help documentation, so be sure to select the Tomcat you are currently binding.

In the following two steps, as in the Jfinal Help document, click the Next button to change the default output folder to Webroot\web-inf\classes.

Click Next and change Content directory to Webroot.

Click Finish to complete the project creation.

Download the Jfinal-1.9-all.zip file on the Jfinal website and unzip it and copy the Jfinal-1.9-bin.jar file from the extracted folder to the Webroot\web-inf\lib folder in your project.

In the project's SRC directory, create a package named Common, under which a class named Democonfig is created, and the class is the entire project's configuration file. Write the following code in Democonfig.

[Java]View Plaincopyprint?
  1. Package common;
  2. Import com.jfinal.config.*;
  3. Public class Democonfig extends Jfinalconfig {
  4. public void Configconstant (Constants me) {
  5. Me.setdevmode (true);
  6. }
  7. public void Configroute (Routes me) {
  8. }
  9. public void Configplugin (Plugins me) {
  10. }
  11. public void Configinterceptor (interceptors me) {
  12. }
  13. public void Confighandler (Handlers me) {
  14. }
  15. }

Create the Indexcontroller class in the common package and fill in the following code into the class:

[Java]View Plaincopyprint?
    1. Package common;
    2. Import Com.jfinal.core.Controller;
    3. Public class Indexcontroller extends Controller {
    4. public Void Index () {
    5. RenderText ("Hello jfinal World");
    6. }
    7. }

Next go back to the Democonfig class and add the following code to the Configroute method:

[Java]View Plaincopyprint?
    1. Me.add ("/", Indexcontroller.   Class);

The purpose of this code is to specify the site's home page path.

Finally, modify the Web. Xml under the Web-inf folder and write the following code:

[HTML]View Plaincopyprint?
  1. <? XML version= "1.0" encoding="UTF-8"?>
  2. <Web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  3. xmlns= "http://java.sun.com/xml/ns/javaee" xmlns:web= "http://java.sun.com/xml/ns/javaee/web-app_ 2_5.xsd "
  4. xsi:schemalocation="Http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd "  
  5. id= "webapp_id" version="2.5">
  6. <filter>
  7. <filter-name>jfinal</filter-name>
  8. <filter-class>com.jfinal.core.jfinalfilter</filter-class>
  9. <init-param>
  10. <param-name>configclass</param-name>
  11. <param-value>common. Democonfig</param-value>
  12. </init-param>
  13. </Filter>
  14. <filter-mapping>
  15. <filter-name>jfinal</filter-name>
  16. <url-pattern>/*</url-pattern>
  17. </filter-mapping>
  18. </Web-app>

It is important to note that the path in <param-value> must be consistent with the path of the project configuration file, where the project configuration file is the Democonfig class in the common package, so the path is common. Democonfig.

Here the project is configured, the following right-click on the project select Run As-->run on severs can be, running results such as.


Here is the problem I encountered in the first configuration, the first is the console package java.net.BindException:Address already in Use:jvm_bind error, the page shows a 404 error. The problem arises because 8080 ports are occupied, and eclipse will of course not be able to create services on port 8080. The general cause of this problem is that Tomcat is running in the system, and you can see whether the following Tomcat process is running in the Task Manager, and then turn it off.
Another problem is that when I first started, I followed the jfinal help document for Tomcat configuration and entered localhost:8080 in the address bar, always displaying a 404 error. And then I understood. In the help document, the project's root directory is bound to the localhost:8080 address in the run of the project, and when Tomcat runs the project, the project root is bound to the "localhost:8080/project name", so enter localhost : 8080 is invalid.

Original address: http://blog.csdn.net/tczhoulan/article/details/42100489

Jfinal Study Notes (i) jfinal environment configuration under Tomcat

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.