JFinal最简单demo---Hello World


JFinal介绍以及包下载路径


http://www.jfinal.com/





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


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


<?xml version="1.0" encoding="ISO-8859-1"?>
<web-app xmlns="http://java.sun.com/xml/ns/javaee"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://java.sun.com/xml/ns/javaee 
         http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
         version="3.0">
    <filter> 
        <filter-name>jfinal</filter-name> 
        <filter-class>com.jfinal.core.JFinalFilter</filter-class> 
        <init-param> 
            <param-name>configClass</param-name> 
            <param-value>com.liangbinny.jfinal.config.DefaultConfig</param-value> 
        </init-param> 
    </filter> 
    <filter-mapping> 
        <filter-name>jfinal</filter-name> 
        <url-pattern>/*</url-pattern> 
    </filter-mapping>
</web-app>



index.jsp

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="windows-31j"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>hello</title>
</head>
<body>
	<h1>hello Jfinal world</h1>
</body>
</html>



整个项目路径:






启动jetty,,访问项目路径


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


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





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




本文例子下载

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



相关推荐
©️2020 CSDN 皮肤主题: 大白 设计师:CSDN官方博客 返回首页