2、maven案例&idexXML调模板&maven运Tomcat报错org.apache.jasper.JasperException: Unable to compile class forJSP

导读:本篇文章讲解 2、maven案例&idexXML调模板&maven运Tomcat报错org.apache.jasper.JasperException: Unable to compile class forJSP,希望对大家有帮助,欢迎收藏,转发!站点地址:www.bmabk.com

报错org.apache.jasper.JasperException: Unable to compile class forJS解决方案

如图,启动服务器成功,但是登陆时报错,原因是6一下版本不兼容jdk1.8

2、maven案例&idexXML调模板&maven运Tomcat报错org.apache.jasper.JasperException: Unable to compile class forJSP

解决办法:
在pom.xml文件下做一下配置

配置tomcat7环境变量
 

  <build>
    <finalName>javaweb</finalName>
    <pluginManagement>
      <plugins>
        <plugin>
            <groupId>org.apache.tomcat.maven</groupId>
          <artifactId>tomcat7-maven-plugin</artifactId>
          <version>2.2</version>
        </plugin>
       </plugins>
    </pluginManagement>
  </build>

点击小图标

2、maven案例&idexXML调模板&maven运Tomcat报错org.apache.jasper.JasperException: Unable to compile class forJSP

 输入Tomcat7:run,因为默认是6.0.29

2、maven案例&idexXML调模板&maven运Tomcat报错org.apache.jasper.JasperException: Unable to compile class forJSP

 部署成功

2、maven案例&idexXML调模板&maven运Tomcat报错org.apache.jasper.JasperException: Unable to compile class forJSP

方法2设置配置模板

配置Tomcat

2、maven案例&idexXML调模板&maven运Tomcat报错org.apache.jasper.JasperException: Unable to compile class forJSP

 点击确定

配置使用文件

2、maven案例&idexXML调模板&maven运Tomcat报错org.apache.jasper.JasperException: Unable to compile class forJSP

 输入Tomcat7+回车,模板就自动创建完成了
2、maven案例&idexXML调模板&maven运Tomcat报错org.apache.jasper.JasperException: Unable to compile class forJSP

配置JDK1.8

 <plugin>
          <groupId>org.apache.tomcat.maven</groupId>
          <artifactId>tomcat7-maven-plugin</artifactId>
          <version>2.2</version>
          <configuration>
            <port>8888</port>
          </configuration>
</plugin>

配置到模板中点击OK

2、maven案例&idexXML调模板&maven运Tomcat报错org.apache.jasper.JasperException: Unable to compile class forJSP

输入jdk1.8回车即可调出模板

maven使用案例

pop.xml配置文件
 

<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>com.itjava</groupId>
  <artifactId>javaweb</artifactId>
  <packaging>war</packaging>
  <version>1.0-SNAPSHOT</version>
  <name>javaweb Maven Webapp</name>
  <url>http://maven.apache.org</url>
  <dependencies>
    <dependency>
      <groupId>javax.servlet</groupId>
      <artifactId>javax.servlet-api</artifactId>
      <version>4.0.0</version>
      <scope>provided</scope>
    </dependency>
    <dependency>
      <groupId>javax.servlet.jsp</groupId>
      <artifactId>jsp-api</artifactId>
      <version>2.0</version>
      <scope>provided</scope>
    </dependency>

    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>4.12</version>
      <scope>test</scope>
    </dependency>
    <dependency>
      <groupId>mysql</groupId>
      <artifactId>mysql-connector-java</artifactId>
      <version>8.0.31</version>
      <scope>runtime</scope>
    </dependency>
    <dependency>
      <groupId>org.junit.jupiter</groupId>
      <artifactId>junit-jupiter</artifactId>
      <version>RELEASE</version>
      <scope>compile</scope>
    </dependency>
  </dependencies>

  <build>
    <finalName>javaweb</finalName>
    <pluginManagement>
      <plugins>
        <plugin>
            <groupId>org.apache.tomcat.maven</groupId>
          <artifactId>tomcat7-maven-plugin</artifactId>
          <version>2.2</version>
          <configuration>
            <port>8888</port>
          </configuration>
        </plugin>
        <plugin>
          <groupId>org.apache.maven.plugins</groupId>
          <artifactId>maven-compiler-plugin</artifactId>
          <configuration>
            <target>1.8</target>
            <source>1.8</source>
            <encoding>UTF-8</encoding>
          </configuration>
        </plugin>
       </plugins>
    </pluginManagement>
  </build>
</project>

Dao接口

package com.itjava.dao;

import com.itjava.domain.Items;


import java.sql.SQLException;
import java.util.List;

public interface  ItemsDao {
    public List<Items> findAll() throws Exception;
}

Dao实现

package com.itjava.dao.impl;

import com.itjava.dao.ItemsDao;
import com.itjava.domain.Items;


import java.sql.*;
import java.util.ArrayList;
import java.util.List;

public class ItemsDaoImpl implements ItemsDao {
    Connection connection=null;
    PreparedStatement pst=null;
    ResultSet rs=null;
    @Override
    public List<Items> findAll() throws Exception {
        List<Items> list = null;
        try {
            Class.forName("com.mysql.cj.jdbc.Driver");
            connection = DriverManager.getConnection("jdbc:mysql:///db?serverTimezone=UTC","root","123456");
            String sql="select * from user";
            pst = connection.prepareCall(sql);
            rs = pst.executeQuery();
            list = new ArrayList<>();
            while(rs.next()){
                Items items = new Items();
                items.setId (rs.getInt("id"));
                items.setName(rs.getString("name"));
                list.add(items);
            }
        } catch (Exception e) {
            throw new RuntimeException(e);
        } finally {
            if (connection!=null){
                connection.close();
            }
            if (pst!=null){
                pst.close();
            }
            if (rs!=null){
                rs.close();
            }
        }
        return list;
    }
}

具体类

package com.itjava.domain;

public class Items {
    private Integer id;
    private String name;

    public Items() {

    }

    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public Items(Integer id, String name) {
        this.id = id;
        this.name = name;
    }
}

测试类
 

package com.itjava.test;


import com.itjava.dao.ItemsDao;
import com.itjava.dao.impl.ItemsDaoImpl;
import com.itjava.domain.Items;
import org.junit.jupiter.api.Test;


import java.util.List;

public class ItemsTest {
    @Test
    public void findAll() throws Exception {
        ItemsDao itemsDao = new ItemsDaoImpl();
        List<Items> list = itemsDao.findAll();
        for (Items i:list){
            System.out.println(i.getName());
        }
    }
}

meven发布tomcat案例

web.xml配置文件

<!DOCTYPE web-app PUBLIC
 "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
 "http://java.sun.com/dtd/web-app_2_3.dtd" >

<web-app>
  <display-name>Archetype Created Web Application</display-name>
  <servlet>
    <servlet-name>MyServlet</servlet-name>
    <servlet-class>com.itjava.servlet.MyServlet</servlet-class>
  </servlet>
  <servlet-mapping>
    <servlet-name>MyServlet</servlet-name>
    <url-pattern>/</url-pattern>
  </servlet-mapping>
</web-app>

跳转jsp页面

<%--
  Created by IntelliJ IDEA.
  User: Administrator
  Date: 2023/1/16 0016
  Time: 17:49
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>Title</title>
</head>
<body>
    hello word
</body>
</html>

servlet

package com.itjava.servlet;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

public class MyServlet extends HttpServlet {
    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        req.getRequestDispatcher("/hello.jsp").forward(req,resp);
    }

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doPost(req, resp);
    }
}

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。

文章由极客之音整理,本文链接:https://www.bmabk.com/index.php/post/81959.html

(0)
小半的头像小半

相关推荐

极客之音——专业性很强的中文编程技术网站,欢迎收藏到浏览器,订阅我们!