将JSP代码从Windows迁移到Linux机器时出错 [英] Error while migrating JSP code from Windows to Linux machine

查看:100
本文介绍了将JSP代码从Windows迁移到Linux机器时出错的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我研究了在Windows系统中的Tomcat5.5服务器上运行的JSP代码.

I worked on a JSP code that is runnning on a Tomcat5.5 server in windows system .

我不得不将所有JSP代码复制到linux系统中,当我执行相同操作时,出现以下错误提示.

I had to copy all the JSP code to a linux system and when I did the same I got an error stating below.

 javax.servlet.ServletException: c:\tmp is not a directory
 Readcsv.init(Readcsv.java:36)
 org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:117)
 org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:174)
 org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:875)


org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.processConnection(Http11BaseProtocol.java:665)
 org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:528)
 org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFollowerWorkerThread.java:81)
 org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:689)
 java.lang.Thread.run(Thread.java:636)

我在Windows系统中修改了没有该c:\ tmp目录的Java代码,然后重新启动了Tomcat服务器,该工具运行正常.

I modified a java code in the windows system without that c:\tmp directory and restarted the tomcat server and the tool worked fine.

当我将Windows的修改后的Java代码替换为linux系统时,仍然出现相同的错误.

When I replaced the modified java code of windows to the linux system, I still get the same error.

注意:我正在使用url http://192.168.0.85:8080/CNA/uploadcsv.jsp从Windows访问linux服务器,其中85是linux的系统号.

Note: Am accessing the linux server from windows using the url http://192.168.0.85:8080/CNA/uploadcsv.jspwhere 85 is the system number of linux.

是否也需要重新启动Tomcat版本的tomcat?如果是这样,该怎么做?

Is there anything like tomcat has to be restarted for the linux version too? If so how to do the same?

更新

这是我在代码中使用c:\​​ tmp位置的地方.

This is where I have used the c:\tmp location in my code.

public class Readcsv extends HttpServlet {
private static final String TMP_DIR_PATH = "c:\tmp";
private File tmpDir;
private static final String DESTINATION_DIR_PATH ="/files";
private File destinationDir;

public void init(ServletConfig config) throws ServletException {
    super.init(config);
    tmpDir = new File(TMP_DIR_PATH);
    if(!tmpDir.isDirectory()) {
        throw new ServletException(TMP_DIR_PATH + " is not a directory");
    }
    String realPath = getServletContext().getRealPath(DESTINATION_DIR_PATH);
    destinationDir = new File(realPath);
    if(!destinationDir.isDirectory()) {
        throw new ServletException(DESTINATION_DIR_PATH+" is not a directory");
    }

}

如何找到临时路径的替代品?目标路径工作正常. 我正是从此示例

How can I find the replacement for the temp path? The destination path works fine. I exactly copied the code from this example

推荐答案

不要在代码中对磁盘文件系统路径进行硬编码.那只是可移植性和可维护性的问题.

Don't hardcode disk file system paths in your code. That's only portability and maintainability trouble.

对于临时文件,请使用

In case of temporary files, rather make use of File#createTempFile().

File tempfile = File.createTempFile("name", ".ext");

无论环境如何,它都会在正确的位置自动创建临时文件.但是,您也可以通过System.getProperty("java.io.tmpdir");获取tmp目录的根目录.

It will automatically create the temp file at the right location, regardless of the environment. You can however also obtain the tmp dir root location by System.getProperty("java.io.tmpdir");.

对于要由您的应用程序读取的资源,只需将它们放在运行时类路径中或将其路径添加到运行时类路径中即可.然后,您可以通过ClassClassLoader上的getResource()getResourceAsStream()方法从类路径中获取它们.

In case of resources which are to be read by your application, just put them in the runtime classpath or add their path to the runtime classpath. Then you can just obtain them from the classpath by getResource() and getResourceAsStream() methods on Class or ClassLoader.

InputStream input = getClass().getResourceAsStream("file.properties");

如果您确实需要在类路径之外具有固定路径,则应在属性文件中对其进行定义,以便至少对应用程序外部的路径具有 any 控制(因此,无需每次都需要更改代码.)

If you really need to have a fixed path outside the classpath, then rather define it in a properties file so that you at least have any control over the path from outside the application (so, without the need to change the code everytime).

String path = properties.getProperty("my.file.path");

这篇关于将JSP代码从Windows迁移到Linux机器时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆