JFinal最简单demo---Hello World


JFinal介绍以及包下载路径


http://www.jfinal.com/


JFinal最简单demo---Hello World_第1张图片



这个包里自带了很多重要的包,比较方面,其中有我们这个最简单的项目用到的


freemarker-2.3.20.jar和jfinal-1.9-bin.jar两个jar包


先定义Controller

package com.liangbinny.jfinal.action;

import com.jfinal.core.Controller;

public class HelloController extends Controller {

	/**
	 * 默认路径
	 */
    public void index() {
        render("/index.jsp");
    }

    /**
     * 指定路径,route里的url+/hello
     */
    public void hello() {
        renderText("Hello JFinal World......");
    }
}



再定义config

package com.liangbinny.jfinal.config;

import com.jfinal.config.Constants;
import com.jfinal.config.Handlers;
import com.jfinal.config.Interceptors;
import com.jfinal.config.JFinalConfig;
import com.jfinal.config.Plugins;
import com.jfinal.config.Routes;
import com.liangbinny.jfinal.action.HelloController;

public class DefaultConfig extends JFinalConfig {

	@Override
	public void configConstant(Constants me) {
		me.setDevMode(true);  
	}

	@Override
	public void configHandler(Handlers arg0) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void configInterceptor(Interceptors arg0) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void configPlugin(Plugins arg0) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void configRoute(Routes me) {
		 me.add("/sayHello", HelloController.class);  
	}

}




配置web.xml




     
        jfinal 
        com.jfinal.core.JFinalFilter 
         
            configClass 
            com.liangbinny.jfinal.config.DefaultConfig 
         
     
     
        jfinal 
        /* 
    



index.jsp

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="windows-31j"%>




hello


	

hello Jfinal world



整个项目路径:


JFinal最简单demo---Hello World_第2张图片



启动jetty,,访问项目路径


http://localhost:8080/JFinalTest/sayHello/


这个默认是直接进入index()方法,访问index.jsp


JFinal最简单demo---Hello World_第3张图片



而访问http://localhost:8080/JFinalTest/sayHello/hello则调用controller里的hello方法,返回text

JFinal最简单demo---Hello World_第4张图片



本文例子下载

http://download.csdn.net/detail/liangbinny/8439085



你可能感兴趣的:(Web前端)