关于java700题的信息
今天给各位分享java700题的知识,其中也会对进行解释,如果能碰巧解决你现在面临的问题,别忘了关注本站,现在开始吧!
本文目录一览:
- 1、1、80端口被占用,Apache启动失败。2、3306端口被占用,MySQL5.1启动失败
- 2、java中action如何获得客户端文件的路径
- 3、JAVA,用List做,两个数组中数的合并和去除相同元素
1、80端口被占用,Apache启动失败。2、3306端口被占用,MySQL5.1启动失败
开始-运行-cmd, 输入 netstat -ano, 看第一列,后面的就是端口,找到80 ,记住对应的PID!!
然后打开任务管理器 查看 - 选择列 - 勾上 PID(进程标识符) - 确定
在任务管理器找到刚才的PID的进程,查看是什么程序占用了端口,把它关闭!!!追问但是4896显示的进程是tomcat6 关闭以后调试没反应啊
回答上面的英文显示 tomcat 已经在另一个进程中运行了, 您再打开就已经重复了。。。是否运行了其他服务器程序,附带启动了comcat 进程
严重: Error starting endpoint
java.net.BindException: Address already in use: JVM_Bind:8080
at org.apache.tomcat.util.net.PoolTcpEndpoint.initEndpoint(PoolTcpEndpoint.java:298)
at org.apache.tomcat.util.net.PoolTcpEndpoint.startEndpoint(PoolTcpEndpoint.java:313)
at org.apache.coyote.http11.Http11BaseProtocol.start(Http11BaseProtocol.java:151)
at org.apache.coyote.http11.Http11Protocol.start(Http11Protocol.java:76)
at org.apache.catalina.connector.Connector.start(Connector.java:1090)
at org.apache.catalina.core.StandardService.start(StandardService.java:457)
at org.apache.catalina.core.StandardServer.start(StandardServer.java:700)
at org.apache.catalina.startup.Catalina.start(Catalina.java:552)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:585)
at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:295)
at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:433)
2009-7-12 15:40:35 org.apache.catalina.startup.Catalina start
严重: Catalina.start:
LifecycleException: service.getName(): "Catalina"; Protocol handler start failed: java.net.BindException: Address already in use: JVM_Bind:8080
at org.apache.catalina.connector.Connector.start(Connector.java:1097)
at org.apache.catalina.core.StandardService.start(StandardService.java:457)
at org.apache.catalina.core.StandardServer.start(StandardServer.java:700)
at org.apache.catalina.startup.Catalina.start(Catalina.java:552)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:585)
at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:295)
at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:433)
2009-7-12 15:40:35 org.apache.catalina.startup.Catalina start
信息: Server startup in 9860 ms
关键信息:
java.net.BindException: Address already in use: JVM_Bind:8080
错误原因:
8080端口被其他的应用占用!
解决方案:
第一步,命令提示符号,执行命令:netstat –ano
Active Connections
Proto Local Address Foreign Address State PID
TCP 0.0.0.0:8080 0.0.0.0:0 LISTENING 656
TCP 0.0.0.0:8080 0.0.0.0:0 LISTENING 656
可见,占用8080端口的进程的PID是656
第二步,命令提示符号,执行命令:tasklist
图像名 PID 会话名 会话# 内存使用
========================= ====== ================ ======== ============
TNSLSNR.exe 656 Console 0 8,992 K
可见,该占用8080端口的进程是TNSLSNR.exe
第三步,通过任务管理器,终止进程TNSLSNR.exe
第四步,重新启动tomcat,即可正常启动
java中action如何获得客户端文件的路径
1.基本概念的理解 绝对路径: 绝对路径就是你的主页上的文件或目录在硬盘上真正的路径,( URL和物理路径)例如: C:\xyz\test.txt代表了test. txt文件的绝对路径。 index.htm也代表了一个 URL绝对路径。 相对路径:相对与某个基准目录的路径。包含Web的相对路径( HTML中的相对目录),例如:在 Servlet中,"/"代表Web应用的跟目录。 和物理路径的相对表示。例如:"./" 代表当前目录, "../"代表上级目录。这种类似的表示,也是属于相对路径。 另外关于URI,URL,URN等内容, 请参考RFC相关文档标准。 RFC 2396: Uniform Resource Identifiers (URI): Generic Syntax, ( rfc2396.txt ) 2.关于JSP/Servlet中的相对路径和绝对路径。 2.1服务器端的地址 服务器端的相对地址指的是相对于你的web应用的地址, 这个地址是在服务器端解析的 (不同于html和javascript中的相对地址, 他们是由客户端浏览器解析的)也就是说这时候 在jsp和servlet中的相对地址应该是相对于你的web应 用,即相对于 webapp/的。 其用到的地方有: forward:servlet中的request. getRequestDispatcher(address); 这个address是 在服务器端解析的,所以,你要forward到a. jsp应该这么写: request.getRequestDispatcher(“ /user/a.jsp”)这个/ 相对于当前的web应用webapp, 其绝对地址就是: webapp/user/a.jsp。 sendRedirect:在jsp中%response. sendRedirect("/rtccp/user/a. jsp");% 2.22、客户端的地址 所有的html页面中的相对地址都是相对于服务器根目录( htt p://192.168.0.1/ )的, 而不是(跟目录下的该Web应用的目录) . 168.0.1/webapp/的 。 Html中的form表单的action属性的地址应该是相对于 服务器根目录( )的, 所以,如果提交到a.jsp为:action="/ webapp/user/a.jsp"或action="%= request.getContextPath()%"/ user/a.jsp; 提交到servlet为actiom="/webapp/ handleservlet" Javascript也是在客户端解析的, 所以其相对路径和form表单一样。 因此,一般情况下,在JSP/HTML页面等引用的CSS, Javascript.Action等属性前面最好都加上 %=request.getContextPath()%, 以确保所引用的文件都属于Web应用中的目录。 另外,应该尽量避免使用类似".","./","../../" 等类似的相对该文件位置的相对路径,这样 当文件移动时,很容易出问题。 3. JSP/Servlet中获得当前应用的相对路径和绝对路径 3.1 JSP中获得当前应用的相对路径和绝对路径 根目录所对应的绝对路径:request. getRequestURI() 文件的绝对路径 :application.getRealPath( request.getRequestURI()); 当前web应用的绝对路径 :application.getRealPath("/"); 取得请求文件的上层目录:new File(application.getRealPath( request.getRequestURI())). getParent() 3.2 Servlet中获得当前应用的相对路径和绝对路径 根目录所对应的绝对路径:request. getServletPath(); 文件的绝对路径 :request.getSession(). getServletContext(). getRealPath (request.getRequestURI()) 当前web应用的绝对路径 :servletConfig. getServletContext(). getRealPath("/"); (ServletContext对象获得几种方式: javax.servlet.http. HttpSession.getServletContext( ) javax.servlet.jsp. PageContext.getServletContext( ) javax.servlet. ServletConfig. getServletContext() ) 4.java 的Class中获得相对路径,绝对路径的方法 4.1单独的Java类中获得绝对路径 根据java.io.File的Doc文挡,可知: 默认情况下new File("/")代表的目录为:System. getProperty("user.dir")。 一下程序获得执行类的当前路径 package org.cheng.file; import java.io.File; public class FileTest { public static void main(String[] args) throws Exception { System.out.println(Thread. currentThread(). getContextClassLoader(). getResource("")); System.out.println(FileTest. class.getClassLoader(). getResource("")); System.out.println( ClassLoader.getSystemResource( "")); System.out.println(FileTest. class.getResource("")); System.out.println(FileTest. class.getResource("/")); //Class文件所在路径 System.out.println(new File("/").getAbsolutePath()); System.out.println(System. getProperty("user.dir")); } } 4.2服务器中的Java类获得当前路径(来自网络) (1).Weblogic WebApplication的系统文件根目录是你的weblo gic安装所在根目录。 例如:如果你的weblogic安装在c:\bea\ weblogic700..... 那么,你的文件根路径就是c:\. 所以,有两种方式能够让你访问你的服务器端的文件: a.使用绝对路径: 比如将你的参数文件放在c:\yourconfig\ yourconf.properties, 直接使用 new FileInputStream("yourconfig/ yourconf.properties"); b.使用相对路径: 相对路径的根目录就是你的webapplication的根路径 ,即WEB-INF的上一级目录,将你的参数文件放 在yourwebapp\yourconfig\ yourconf.properties, 这样使用: new FileInputStream("./yourconfig/ yourconf.properties"); 这两种方式均可,自己选择。 (2).Tomcat 在类中输出System.getProperty("user. dir");显示的是%Tomcat_Home%/bin (3).Resin 不是你的JSP放的相对路径, 是JSP引擎执行这个JSP编译成SERVLET 的路径为根.比如用新建文件法测试File f = new File("a.htm"); 这个a.htm在resin的安装目录下 (4).如何读相对路径哪? 在Java文件中getResource或getResourc eAsStream均可 例:getClass(). getResourceAsStream(filePath); //filePath可以是"/filename",这里的/ 代表web 发布根路径下WEB-INF/classes 默认使用该方法的路径是:WEB-INF/classes。 已经在Tomcat中测试。 5.读取文件时的相对路径,避免硬编码和绝对路径的使用。( 来自网络) 5.1 采用Spring的DI机制获得文件,避免硬编码。 参考下面的连接内容: viewtopic.php?p=90213 5.2 配置文件的读取 参考下面的连接内容: article/39/39681.shtm 5.3 通过虚拟路径或相对路径读取一个xml文件,避免硬编码 参考下面的连接内容: clubPage.jsp?iPage=1tID= 10708ccID=8 6.Java中文件的常用操作(复制,移动,删除,创建等)( 来自网络) 常用 java File 操作类 200604022353065155.htm Java文件操作大全(JSP中) pcedu/empolder/gj/java/0502/ 559401.html java文件操作详解(Java中文网) 2005/1108/10947.htm JAVA 如何创建\删除\修改\复制目录及文件 developer/java/2005/2/264.html 总结: 通过上面内容的使用,可以解决在Web应用服务器端, 移动文件,查找文件,复制 删除文件等操作,同时对服务器的相对地址, 绝对地址概念更加清晰。 建议参考URI,的RFC标准文挡。同时对Java.io. File. Java.net.URI.等内容了解透彻 对其他方面的理解可以更加深入和透彻。
JAVA,用List做,两个数组中数的合并和去除相同元素
package com.ajax.test;
import java.io.File;
import java.io.FileWriter;
import java.util.Arrays;
/**
* 把一个数组的元素复制到另个数组; 去除重复元素不能用SET集合; 每次复制的记录输到一个文件里
*
* @author ajax_2003
* @version 1.0, 2009-7-26
*
*/
public class CopyArrayAndRemoveDuplicate {
private static String FILE_PATH = "d:/abc.txt";
private static File file;
static {
file = new File(FILE_PATH);
}
/**
* 取出冗余数据
*
* @param nums
* 原数组
*/
private int[] removeDuplicate(int[] nums) throws Exception {
int[] tmpArray = new int[nums.length];
int count = 0;
loop: //
for (int i = 0; i nums.length; i++) {
int tmp = nums[i];
for (int j = 0; j count; j++) {
if (tmp == tmpArray[j])
continue loop;
}
tmpArray[count++] = tmp;
log("成功复制了元素" + tmp);// 写日志
}
return copyArray(tmpArray, 0, count);
}
/**
* 拷贝数组
*
* @param srcArray
* 要拷贝的数组
* @param startIndex
* 拷贝起始索引
* @param endIndex
* 拷贝结束索引
* @return 结果数组
*/
private int[] copyArray(int[] srcArray, int startIndex, int endIndex)
throws Exception {
if (endIndex = startIndex)
throw new Exception("Argumens wrong!");
int[] desArray = new int[endIndex - startIndex];
System.arraycopy(srcArray, startIndex, desArray, 0, desArray.length);
return desArray;
}
/**
* 输出操作日志(即: 每次复制的记录输到一个文件里)
*
* @param oprate
*/
private void log(String oprate) {
FileWriter out = null;
try {
out = new FileWriter(file, true);
out.write(oprate + "\r\n");
} catch (Exception e) {
e.printStackTrace();
} finally {
try {
if (out != null)
out.close();
out = null;
} catch (Exception ex) {
ex.printStackTrace();
}
}
}
public static void main(String[] args) {
int[] nums = { 1, 223, 1, 2, 2, 2, 3, 2, 3, 34, 45, 5, 5, 3, 23, 2, 2,
3, 4, 5, 5, 6, 7, 78, 8, 9, 34, 90, 45, 675, 4, };
int[] finalArray;
try {
finalArray = new CopyArrayAndRemoveDuplicate()
.removeDuplicate(nums);
System.out.println(Arrays.toString(finalArray));
} catch (Exception e) {
e.printStackTrace();
}
}
}
有些地方可能考虑的不完全,见谅!
//合并数组并排序
public void arrCopy() {
int[] a = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
int[] b = { 100, 200, 300, 400, 500, 600, 700, 800, 900, 1000 };
System.arraycopy(a, 2, b, 5, 5);
for(int n : b){
System.out.print(n+",");
}
System.out.println();
}
//去掉重复元素
public static void main(String args[]) {
int[] arr = { 1, 2, 2, 3, 3, 4, 4, 5, 5, 5, 6, 6, 7, 8, 9, 9, 10, 11, 11,
11, 12, 12, 13, 14, 14, 15 }; // 预设数据数组
int index = 1; // 保存最后一个不重复的位置
int last = arr[0];
for (int i = 1; i arr.length; i++) {
if (arr[i] != last) {
arr[index] = arr[i];
last = arr[index];
index++;
}
}
int[] rtn = new int[index];
System.arraycopy(arr, 0, rtn, 0, index);
System.out.println(Arrays.toString(rtn));
}
java700题的介绍就聊到这里吧,感谢你花时间阅读本站内容,更多关于、java700题的信息别忘了在本站进行查找喔。
发布于:2022-12-18,除非注明,否则均为
原创文章,转载请注明出处。