jetty 8.0不能识别jsp中的脚本语法

使用jetty8.0调试项目时,页面会出现这样的问题,查了两天项目,没能确定问题发生的原因,希望大牛们能帮帮忙:image.pngimage.png

依赖:

<project xmlns="http://maven.apache.org/POM/4.0.0"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>pers.lu</groupId>
    <artifactId>JFinalMall</artifactId>
    <packaging>war</packaging>
    <version>0.0.1-SNAPSHOT</version>
    <name>JFinalMall Maven Webapp</name>
    <url>http://maven.apache.org</url>
    <profiles>
        <profile>
            <id>default-tools.jar</id>
            <activation>
                <property>
                    <name>java.vendor</name>
                    <value>Sun Microsystems Inc.</value>
                </property>
            </activation>
            <dependencies>
                <dependency>
                    <groupId>com.sun</groupId>
                    <artifactId>tools</artifactId>
                    <version>1.6.0</version>
                    <scope>system</scope>
                    <systemPath>${env.JAVA_HOME}/lib/tools.jar</systemPath>
                </dependency>
            </dependencies>
        </profile>
    </profiles>
    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <maven.compiler.encoding>UTF-8</maven.compiler.encoding>
    </properties>
    <!-- 使用阿里 maven 库 -->
    <repositories>
        <repository>
            <id>ali-maven</id>
            <url>http://maven.aliyun.com/nexus/content/groups/public</url>
            <releases>
                <enabled>true</enabled>
            </releases>
            <snapshots>
                <enabled>true</enabled>
                <updatePolicy>always</updatePolicy>
                <checksumPolicy>fail</checksumPolicy>
            </snapshots>
        </repository>
    </repositories>
    
    <dependencies>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>3.8.1</version>
            <scope>test</scope>
        </dependency>
        <!-- 此处的 scope 值为 compile 仅为支持 IDEA下启动项目.打war包时需要改成 provided,以免将一些无用的jar打进去 -->
        <dependency>
            <groupId>com.jfinal</groupId>
            <artifactId>jetty-server</artifactId>
            <version>8.1.8</version>
            <scope>compile</scope>
        </dependency>
        <dependency>
            <groupId>com.jfinal</groupId>
            <artifactId>jfinal</artifactId>
            <version>3.4</version>
        </dependency>
        <dependency>
            <groupId>log4j</groupId>
            <artifactId>log4j</artifactId>
            <version>1.2.16</version>
        </dependency>
        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <version>5.1.44</version>
        </dependency>
        <dependency>
            <groupId>com.alibaba</groupId>
            <artifactId>druid</artifactId>
            <version>1.0.29</version>
        </dependency>
        <dependency>
            <groupId>com.jfinal</groupId>
            <artifactId>cos</artifactId>
            <version>2017.5</version>
        </dependency>
        <dependency>
            <groupId>org.apache.commons</groupId>
            <artifactId>commons-lang3</artifactId>
            <version>3.8</version>
        </dependency>
        <dependency>
            <groupId>commons-codec</groupId>
            <artifactId>commons-codec</artifactId>
            <version>1.8</version>
        </dependency>
        <!-- 新版本 jfinal 在用整合的 Jetty 启动时,需要使用下面的 depencency.
        如果是 IDEA 下开发,要将 scope 改成 compile,在打 war 包时注意要再改回来
        成为 provided,独立部署用的容器大多都有 jsp 支持的 jar 包 -->
        <!-- jsp support by jetty -->
        <dependency>
            <groupId>org.eclipse.jetty</groupId>
            <artifactId>jetty-jsp</artifactId>
            <version>8.1.8.v20121106</version>
            <scope>provided</scope>
        </dependency>
        <!-- jstl相关jar包 -->
        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>javax.servlet-api</artifactId>
            <version>3.0.1</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>javax.servlet.jsp</groupId>
            <artifactId>jsp-api</artifactId>
            <version>2.1</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>jstl</artifactId>
            <version>1.2</version>
        </dependency>
    </dependencies>
    <build>
        <finalName>JFinalMall</finalName>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>2.3.2</version>
                <configuration>
                    <source>1.6</source>
                    <target>1.6</target>
                </configuration>
            </plugin>
            <!-- This plugin will help you pre-compile your jsps
             and works in conjunction with the Maven war plugin
             to put them inside an assembled war. -->
            <plugin>
                <groupId>org.eclipse.jetty</groupId>
                <artifactId>jetty-jspc-maven-plugin</artifactId>
                <version>9.4.12.v20180830</version>
                <executions>
                    <execution>
                        <id>jspc</id>
                        <goals>
                            <goal>jspc</goal>
                        </goals>
                        <configuration>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>
</project>

路由:

package pers.lu.route;
import com.jfinal.config.Routes;
import pers.lu.controller.IndexController;
public class IndexRoutes extends Routes {
    @Override
    public void config() {
        setBaseViewPath("index");
        add("/index",IndexController.class);
    }
}

config类

package pers.lu.common;
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.core.JFinal;
import com.jfinal.ext.handler.ContextPathHandler;
import com.jfinal.kit.PropKit;
import com.jfinal.plugin.activerecord.ActiveRecordPlugin;
import com.jfinal.plugin.druid.DruidPlugin;
import com.jfinal.render.ViewType;
import com.jfinal.template.Engine;
import pers.lu.common.model.Good;
import pers.lu.common.model.User;
import pers.lu.controller.IndexController;
import pers.lu.route.ActionRoutes;
import pers.lu.route.IndexRoutes;
public class DemoConfig extends JFinalConfig {
    public static void main(String[] args) {
        JFinal.start("src/main/webapp", 8080, "/");
    }
    @Override
    public void configConstant(Constants arg0) {
        // 读取配置文件,也可以使用PropKit
        PropKit.use("a_little_config.txt");
        arg0.setDevMode(true);
        arg0.setEncoding("UTF-8");
        // arg0.setViewType(ViewType.JSP);
    }
    @Override
    public void configRoute(Routes arg0) {
        // 控制个人中心
        arg0.add(new IndexRoutes());
        arg0.add(new ActionRoutes());
    }
    @Override
    public void configEngine(Engine arg0) {
        // TODO Auto-generated method stub
    }
    @Override
    public void configHandler(Handlers arg0) {
        // 用于保证上下文正确,防止文件更新以后,样式表丢失
        arg0.add(new ContextPathHandler("ctx"));
    }
    @Override
    public void configInterceptor(Interceptors arg0) {
    }
    // 使用getModel()方法前必须要启动ARP
    @Override
    public void configPlugin(Plugins arg0) {
        // 根据键值对找到对应的值
        DruidPlugin druidPlugin = new DruidPlugin(PropKit.get("jdbcUrl"), PropKit.get("user"), PropKit.get("password"));
        arg0.add(druidPlugin);
        ActiveRecordPlugin arp = new ActiveRecordPlugin(druidPlugin);
        //数据库链接池
        arg0.add(arp);
        arp.addMapping("t_user", User.class);
        arp.addMapping("t_goods", Good.class);
        // 设置SqlTemplate的基准路径,SqlTemplate是一个sql文件,即建立数据库
        /*arp.setBaseSqlTemplatePath(PathKit.getWebRootPath() + "/WEB-INF");
        arp.addSqlTemplate("/sql/Mall.sql");*/
        
    }
}

controller类

package pers.lu.controller;
import com.jfinal.config.Plugins;
import com.jfinal.core.Controller;
import com.jfinal.plugin.activerecord.Page;
import pers.lu.common.model.Good;
import pers.lu.common.model.User;
public class IndexController extends Controller {
    public void index() {
        // 参数二为默认值,即当msg为空时,取defaultValue为msg的值
        // URL范例:http://localhost:8080/index?msg=123
        // String msg = getPara("msg", "defaultValue");
        // msg要在前端显示的话需要写成#(msg)
        // setAttr("msg", "Hello World!" + msg);
        // getParaToInt(0, 1)的意思是取得第一个参数值,没有的话默认为1
        // 记得绑定Model,即在public void configPlugin(Plugins arg0)中添加
        Page<Good> goodList = Good.dao.paginate(getParaToInt(0, 1), 10);
        setAttr("goodList", goodList);
        // 渲染名为 test.html 的视图,且视图类型为 JFinal Template
        // renderTemplate("/WEB-INF/index.html");
        // 商品主页面
        // renderJson(goodList);
         render("/index.jsp");
    }
}

项目没有报错,只是不能识别脚本程序。再次感谢大牛的帮助。

评论区

天朝子民

2018-09-13 10:13

默认用的是enjoy,用jsp需要在youconfig里设置下。

ddjfinal

2018-09-13 11:18

摒弃jsp吧,老难用了,就用jfinal自带的enjoy吧,炒鸡好用,谁用谁知道

FlameLord01

2018-09-14 18:53

@ddjfinal 只能这样么,那好吧,我去学学enjoy,谢谢。

FlameLord01

2018-09-14 18:54

@天朝子民 那我去学学enjoy吧,谢谢

热门反馈

扫码入社