服务器tomcat中的no文件,安装Tomcat出现的问题

在win10安装了JDK9并配置好了相关路径,在Tomcat在启动过程中出现startup.bat时闪退。

先要找出问题的原因:右键编辑打开“startup.bat"文件,然后找文件的最后一行代码是:end 在:end的后面输入pause如下图所示:

接下来在DOS命令窗口运行startup.bat,此时提示报错信息如下:the JRE_HOME environment variable is not defined correctly This environment variabl

原因知道了,下面来看解决办法:

1、分析startup.bat启动脚本:发现其调用了catalina.bat,而catalina.bat调用了setclasspath.bat

2、在setclasspath.bat的头部定义了JAVA_HOME和JRE_HOME的值,那么这里需要我们手动设置JAVA_HOME变量和JRE_HOME变量(红色代码为新添加

注意:你所设置的变量要和自己的电脑中”环境变量“里的JAVA_HOME和JRE_HOME保持一致,我的是红色的代码。

第一还是配错了路径,是应为环境变量中JRE_HOME的问题。错把jre的绝对路径放在JAVA_HOME中了。把JAVA_HOME中的jre的绝对路径删除掉。重新建一个JRE_HOME,并且加入jre的绝对路径。改完后就如下

@echo off

rem Licensed to the Apache Software Foundation (ASF) under one or more

rem contributor license agreements. See the NOTICE file distributed with

rem this work for additional information regarding copyright ownership.

rem The ASF licenses this file to You under the Apache License, Version 2.0

rem (the “License”); you may not use this file except in compliance with

rem the License. You may obtain a copy of the License at

rem

rem http://www.apache.org/licenses/LICENSE-2.0

rem

rem Unless required by applicable law or agreed to in writing, software

rem distributed under the License is distributed on an “AS IS” BASIS,

rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.

rem See the License for the specific language governing permissions and

rem limitations under the License.

rem ---------------------------------------------------------------------------

rem Set JAVA_HOME or JRE_HOME if not already set, ensure any provided settings

rem are valid and consistent with the selected start-up options and set up the

rem endorsed directory.

rem ---------------------------------------------------------------------------

set JAVA_HOME=D:\D:\tomcat\apache-tomcat-8.5.43

set JRE_HOME= C:\Program Files\Java\jre-9.0.4

rem Make sure prerequisite environment variables are set

rem In debug mode we need a real JDK (JAVA_HOME)

if “”%1"" == ““debug”” goto needJavaHome

rem Otherwise either JRE or JDK are fine

if not “%JRE_HOME%” == “” goto gotJreHome

if not “%JAVA_HOME%” == “” goto gotJavaHome

echo Neither the JAVA_HOME nor the JRE_HOME environment variable is defined

echo At least one of these environment variable is needed to run this program

goto exit

:needJavaHome

rem Check if we have a usable JDK

if “%JAVA_HOME%” == “” goto noJavaHome

if not exist “%JAVA_HOME%\bin\java.exe” goto noJavaHome

if not exist “%JAVA_HOME%\bin\javaw.exe” goto noJavaHome

if not exist “%JAVA_HOME%\bin\jdb.exe” goto noJavaHome

if not exist “%JAVA_HOME%\bin\javac.exe” goto noJavaHome

set “JRE_HOME=%JAVA_HOME%”

goto okJava

:noJavaHome

echo The JAVA_HOME environment variable is not defined correctly.

echo It is needed to run this program in debug mode.

echo NB: JAVA_HOME should point to a JDK not a JRE.

goto exit

:gotJavaHome

rem No JRE given, use JAVA_HOME as JRE_HOME

set “JRE_HOME=%JAVA_HOME%”

:gotJreHome

rem Check if we have a usable JRE

if not exist “%JRE_HOME%\bin\java.exe” goto noJreHome

if not exist “%JRE_HOME%\bin\javaw.exe” goto noJreHome

goto okJava

:noJreHome

rem Needed at least a JRE

echo The JRE_HOME environment variable is not defined correctly

echo This environment variable is needed to run this program

goto exit

:okJava

rem Don’t override the endorsed dir if the user has set it previously

if not “%JAVA_ENDORSED_DIRS%” == “” goto gotEndorseddir

rem Set the default -Djava.endorsed.dirs argument

set “JAVA_ENDORSED_DIRS=%CATALINA_HOME%\endorsed”

:gotEndorseddir

rem Don’t override _RUNJAVA if the user has set it previously

if not “%_RUNJAVA%” == “” goto gotRunJava

rem Set standard command for invoking Java.

rem Also note the quoting as JRE_HOME may contain spaces.

set _RUNJAVA="%JRE_HOME%\bin\java.exe"

:gotRunJava

rem Don’t override _RUNJDB if the user has set it previously

rem Also note the quoting as JAVA_HOME may contain spaces.

if not “%_RUNJDB%” == “” goto gotRunJdb

set _RUNJDB="%JAVA_HOME%\bin\jdb.exe"

:gotRunJdb

goto end

:exit

exit /b 1

:end

exit /b 0

添加变量后保存,并关闭文件,重新启动tomcat,然后在点击startup.bat,看到下面这样就说明OK了

如果是启动后再次启动出现问题,可能是你没有关闭之前启动的,造成8080端口占

有两种方案:

1.在startup.bat 同级目录中,按 shutdown.bat 关闭 (建议用此方法)

2.Tomcat服务器的配置文件,全部都在tomcat的安装目录下conf目录下:修改tomcat的端口为9090修改完server.xml文件必须重启服务器才能有效。 通过浏览器的地址栏访问测试:http://localhost:9090

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
以下是用Java实现文件上传到Tomcat服务器的步骤: 1. 创建一个Java Web项目并添加所需的jar包,如commons-fileupload.jar和commons-io.jar。 2. 创建一个Servlet,用于处理文件上传请求。在doPost方法,通过FileItemFactory和ServletFileUpload类解析请求并获取上传的文件。 ``` protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { // Check that we have a file upload request boolean isMultipart = ServletFileUpload.isMultipartContent(request); if (!isMultipart) { response.getWriter().println("No file uploaded"); return; } // Create a factory for disk-based file items DiskFileItemFactory factory = new DiskFileItemFactory(); // Set the temporary directory to store uploaded files File tempDir = new File(System.getProperty("java.io.tmpdir")); factory.setRepository(tempDir); // Create a new file upload handler ServletFileUpload upload = new ServletFileUpload(factory); // Parse the request to get file items List<FileItem> items = null; try { items = upload.parseRequest(request); } catch (FileUploadException e) { response.getWriter().println("File upload failed"); return; } // Process the uploaded file for (FileItem item : items) { if (!item.isFormField()) { // Get the uploaded file name and save it to disk String fileName = item.getName(); File uploadedFile = new File(getServletContext().getRealPath("/uploads"), fileName); item.write(uploadedFile); } } response.getWriter().println("File upload successful"); } ``` 3. 在web.xml文件配置Servlet映射和文件上传大小限制等参数。 ``` <servlet> <servlet-name>FileUploadServlet</servlet-name> <servlet-class>com.example.FileUploadServlet</servlet-class> </servlet> <servlet-mapping> <servlet-name>FileUploadServlet</servlet-name> <url-pattern>/upload</url-pattern> </servlet-mapping> <!-- Set the maximum file size to 10MB --> <context-param> <param-name>maxFileSize</param-name> <param-value>10485760</param-value> </context-param> <!-- Set the maximum request size to 15MB --> <context-param> <param-name>maxRequestSize</param-name> <param-value>15728640</param-value> </context-param> ``` 4. 创建一个HTML表单,用于选择要上传的文件并提交到Servlet处理。 ``` <form action="upload" method="post" enctype="multipart/form-data"> <input type="file" name="file" required><br> <input type="submit" value="Upload"> </form> ``` 5. 将项目部署到Tomcat服务器,并访问HTML表单页面上传文件。 以上就是用Java实现文件上传到Tomcat服务器的步骤。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值