Tag Archives: tomcat

Tomcat starts front-end engineering error [How to Solve]

I tried all the methods mentioned on the Internet and asked my colleagues, but they didn’t solve them. Finally, I inadvertently remembered to delete the target and out directories, and the results were good… Is there a great God to explain?

At the same time, note that the default band should be deleted and only a backslash should be retained

[Solved] SpringMVC Run Error: SEVERE-Servlet.service() for servlet jsp threw exception

Today, I was learning spring MVC. Everything was difficult at the beginning. I didn’t expect it to be so difficult. The most basic Hello World was trapped for half an hour. The main problem was that Tomcat 10 version didn’t adapt to and Maven relied on. The error was: servlet. Service () for servlet JSP thread exception Java. Lang. NullPointerException , and the following is the specific solution

Read the original text

At the beginning of writing dependency, I found that groupid in the book was javax , and I had suffered such a loss before. In order to adapt it to my Tomcat 10, I changed it to Jakarta . As a result, when writing controller , the method can only recognize javax , and I can’t change the source code again, There is no way to replace dependence with this

<dependency>
    <groupId>javax.servlet</groupId>
    <artifactId>javax.servlet-api</artifactId>
    <version>4.0.1</version>
</dependency>
<dependency>
    <groupId>javax.servlet.jsp</groupId>
    <artifactId>javax.servlet.jsp-api</artifactId>
    <version>2.3.3</version>
</dependency>

Not surprisingly, when the Tomcat server is executed, it always reports an error saying that org.springframework.web.servlet.dispatcherservlet in the configuration file is not a servlet, so there is no way but to change the method

I thought Maven could play Tomcat plug-in and paste the dependent code immediately

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

Continue to run and report an error: servlet. Service () for servlet JSP thread exception Java. Lang. NullPointerException , go to stackoverflow and say that the range must be set to provided , and then run to display it. Later, switch back to normal tomcat operation with a try state, but the result is still not good

PS: finally switched back to Tomcat version 9.052

Resolve the idea error unable to Ping server at localhost: 1099 exception

Unable to Ping server at localhost: 1099
the solutions mentioned on the Internet are the first two, but mine is the third. I hope small partners can avoid the pit
1. The version of Tomcat and JDK matches
port 2 is occupied
3 check the idea configuration Tomcat. VM options cannot have spaces before and after the equals sign
(if there are spaces before and after the equals sign, there will always be an error.)

java.lang.IllegalStateException: Cannot call sendRedirect() after the response has been committed

Error message: java.lang.illegalstateexception: cannot call sendredirect() after the response has been committed java.lang.illegalstateexception


Error message parsing: redirection cannot be called after response

Basic overview of Servlet

    determine whether it is necessary to use redirection. If necessary, use redirection. Otherwise, continue the work of servlet

    Cause of error:

      when using retargeting, our page has jumped, and the retargeted code will not be able to perform work. In order to make the jump page unaffected, we add a return after retargeting (most likely) the doget() and dopost() methods in servlet are incomplete. For example, write a doget() method less and delete the super. Doget() and super. Dopost() in the doget() and dopost() methods after rewriting; Here, we can use a request method to receive parameters. For example, the client uses the post or get request to send parameters, and we receive and respond consistently using the get method. At this time, we can add the code dopost (request, response) in the dopost () method check whether the program logic causes multiple jumps

      Note: when we write the redirection path. Redirection supports both the project resources and the resources in the server to use redirection, so the general redirection path is /project resource name/page or servlet to be redirected to or write the relative path directly

Solution to javax.naming.noinitialcontextexception error

When using DBCP to configure data sources, a test class was written. In the test class, DBCP was called to get the database connection error: javax.naming.NoInitialContextException: Need to specify class name in environment or or in,

Check whether the dependent jar package is imported:
commons-dbcp2-2.8.0. Jar
commons-pool2-2.10.0. Jar
mysql8.0 jar package
mysql5.0 jar package

Test code:

package test;

import org.junit.Test;
import tools.DataSourceUtil;

import java.sql.Connection;

public class test {
    @Test
    public void test(){
        Connection connection = DataSourceUtil.getConnection();
        System.out.println(connection);
    }
}

Database source code:

package tools;

import javax.naming.InitialContext;
import javax.naming.NamingException;
import javax.sql.DataSource;
import java.sql.Connection;
import java.sql.SQLException;

public class DataSourceUtil {

    // Get the connection
    public static Connection getConnection() {
        // ctrl + alt + t --- select 6
        // instantiate the object of the initial context
        Connection connection = null;
        try {
            InitialContext initialContext = new InitialContext();
            // Get the data in the configuration and get the object object
            Object lookup = initialContext.lookup("java:comp/env/jdbc/easybuy");
            // unboxing strong turn to get the connection pool
            DataSource ds = (DataSource) lookup;
            // get the connection pool to give me a connection
            connection = ds.getConnection();
        } catch (NamingException e) {
            e.printStackTrace();
        } catch (SQLException throwables) {
            throwables.printStackTrace();
        }
        // Return to link
        return connection;
    }

    // close connection
    public static void closeConnection(Connection connection) {
        if (connection != null) {
            try {
                connection.close();
            } catch (SQLException throwables) {
                throwables.printStackTrace();
            }
        }
    }
}

Bug map:

reason:

When DBCP is used to connect to the database, the main function is always used to test. The initialcontext is only available in the context of the web application server. While the configuration file is in the web directory, it is obvious that if initialcontext wants to access the configuration file, it must run on the web server to connect to the database and get the connection object

It can’t be tested directly with the main function, it can only be displayed in Tomcat or servlet or JSP

Running results:

#Successfully get the connection object!

After modifying the Tomcat configuration file in development, the modified configuration file will be automatically restored after ecplise starts Tomcat

The causes of the problem are as follows:


The reason is that when Tomcat is added in eclipse, eclipse will automatically store the Tomcat configuration file. When the Tomcat server starts in eclipse, it will replace the original Tomcat configuration file with its stored Tomcat configuration file.


resolvent:


1. Set ecplise to cancel the automatic publishing function

    in ecplise, select window preferences server launching to cancel automatically publishing Wen starting servers and click OK to finish operation

    2. In ecplise project, there is a server project, a Tomcat VX. X server at localhost config, in which there are configuration files to modify the files directly. When Tomcat is republished, it will use the configuration files here to cover the files in conf under Tomcat

Tomcat startup project warning: org.apache.jasper.servlet.tldscanner.scanjars at least one jar has been scanned for TLD but does not contain TLD

Problem:
start springmvc project, start error:
org.apache.jasper.servlet.tldscanner.scanjars at least one jar is scanned for TLD, but it does not contain TLD. Enable debug logging for this logger to get a complete list of jars that have been scanned but in which TLDs were not found. Skipping unnecessary jars during scanning can reduce startup time and JSP compilation time.

Solution:
1. Find the catalina.properties file in the conf directory under your Tomcat installation path:

2. Change the content after the equal sign in the figure below to *. Jar

3. Then reconfigure your own server and restart it.

[Solved] Tomcat7 Start Error: Failed to start component [StandardEngine[Catalina].StandardHost[localhost].StandardCon

When transforming a project in eclipse, tomcat7 is always started

Failed to start component [StandardEngine[Catalina].StandardHost[localhost].StandardContext[/AtomLocal]]

terms of settlement:

Right click project properties, find deployment assembly, add Java build path entries and Maven dependencies

Idea unified setting code to UTF-8 code and solution of Tomcat garbled code

Modify project space code

File-> Settings-> Editor-> File encodings
check the bottom box

Modifying the relevant configuration in Tomcat

Step 1: modify Tomcat configuration file and add UTF-8 code

Change the service.xml configuration in Tomcat's conf folder to add URIEncoding="UTF-8", as follows.

<Connector port="8080" protocol="HTTP/1.1" ​ connectionTimeout="20000" ​ redirectPort="8443" URIEncoding="UTF-8"/>

It was found that the start-up condition remained unchanged

Step 2: change the idea configuration and set the encoding to UTF-8

Refer to the above method

Step 3: modify the parameters in logging. Properties under conf of Tomcat

Change java.util.logging.ConsoleHandler.encoding = GBK

to

java.util.logging.ConsoleHandler.encoding = UTF-8

T omcat:removeGeneratedFiles Failed to delete the generated java file solution

Questions

Phenomenon

        Tomcat service startup: JSP page returns 404 phenomenon

Log analysis

02-jun-2021 16:17:30.174 warning [http-nio-8080-exec-14] org.apache.jasper.compiler.compiler.removegeneratedfiles failed to delete the generated java file [E:// cloudvos/apache-tomcat-9.0.39-windows-x64/apache-tomcat-9.0.39/work/Catalina/localhost/CS/org/Apache/JSP/Web]_ 002dINF\views\modules\ri\communityList_ jsp.java]

solve

         File permissions caused by the problem, delete all cache files

Delete the contents of apache-tomcat-9.0.7

Delete the contents of apache-tomcat-9.0.7

Tomcat — failed to start, flash back

Tomcat server failed to start

Reason: the project was configured before, but the project folder was accidentally deleted later. As a result, when the project was started, an error was flashed back.

Solution: open the server.xml configuration file in the conf folder of Tomcat installation directory and delete it

<Context path="" docBase="..." reloadable="true"/>

This is just one line of code.