官方手册虽然写的很详细但是忽略的很多小的细节方面,不看源码,网络资料又少,很多新手找不到解决办法。所以养成出了问题,多看源码的习惯

部署helloJFinal

  • 项目结构

JFinal快速上手及注意事项-LMLPHP

    -

  • 相关代码
  • `package demo;

import com.jfinal.core.Controller;

public class myControll extends Controller{

public void index() {
this.renderText("hello jfinal");
}

}

`


package demo; 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.jfinal.template.Engine; public class projectConfig extends JFinalConfig{ @Override
public void configConstant(Constants me) {
// TODO Auto-generated method stub
me.setDevMode(true);
} @Override
public void configRoute(Routes me) {
// TODO Auto-generated method stub
me.add("/hello", myControll.class);
} @Override
public void configEngine(Engine me) {
// TODO Auto-generated method stub } @Override
public void configHandler(Handlers me) {
// TODO Auto-generated method stub } @Override
public void configInterceptor(Interceptors me) {
// TODO Auto-generated method stub } @Override
public void configPlugin(Plugins me) {
// TODO Auto-generated method stub } }

-webxml

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://java.sun.com/xml/ns/javaee"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
id="WebApp_ID" version="2.5">
<display-name>JFinalDemo</display-name>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
<welcome-file>index.htm</welcome-file>
<welcome-file>index.jsp</welcome-file>
<welcome-file>default.html</welcome-file>
<welcome-file>default.htm</welcome-file>
<welcome-file>default.jsp</welcome-file>
</welcome-file-list>
<filter>
<filter-name>jfinal</filter-name>
<filter-class>com.jfinal.core.JFinalFilter</filter-class>
<init-param>
<!-- 在tomcat部署下,这里必须是configClass 源码要求
jetty server 则随便做
-->
<param-name>configClass</param-name>
<param-value>demo.projectConfig</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>jfinal</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
</web-app>

关于

JFinal.start("WebContent", 80, "/",5);

官方文件写的是 Jfinal.start(“src/main/webapp”,80,”/”,5);

其实这个路径写了 “/”就代表采用相对路径 而 默认执行index()方法 ,如果 全部写出来,即为 http://localhost/hello/index 其他方法修改 index为你想要的方法即可

05-11 04:02