小编LGA*_*GAP的帖子

如何更改TOMCAT使用的Java版本?

我的系统上安装了Java 1.6和Tomcat 5.5.

但是Tomcat 5.5访问Java 1.5,因此结果我在Bad version number in .class file使用JSP执行java代码时遇到错误.

如何将Tomcat版本更改为Java 1.6?

UPDATE

我尝试更改tomcat5w.exe指向1.6版本的JVM,现在我没有Bad version in .class file出错.但现在,我收到以下错误.

exception

org.apache.jasper.JasperException
org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:498)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:411)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:308)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:259)
javax.servlet.http.HttpServlet.service(HttpServlet.java:729)

root cause

java.lang.NullPointerException
myfirst.SearchLink.checkURL(SearchLink.java:20)
org.apache.jsp.Test_jsp._jspService(Test_jsp.java:52)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:98)
javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:369)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:308)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:259)
javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
Run Code Online (Sandbox Code Playgroud)

可能是根本原因?

java jsp tomcat tomcat5.5 java-home

45
推荐指数
4
解决办法
16万
查看次数

如何让java程序同时打印out.println()和err.println()语句?

我编写了下面的java代码,它执行另一个名为"Newsworthy_RB"的java程序.

Newsworthy_RB.java包含System.out.printlln()和System.err.println()语句.

我希望在命令提示符控制台中打印输出.

为了获得相同的东西,必须做些什么.

下面的程序只打印out.println()语句而不是err.println()语句.

请告诉我下面的代码是否会像我期望的那样发挥作用?

command = "java -cp .:../sqljdbc.jar SetHash Newsworthy_RB";
Process child1 = Runtime.getRuntime().exec(command);
InputStream in1 = child1.getErrorStream();
InputStream in2 = child2.getInputStream();
while ((c = in1.read()) != -1 || (c = in2.read()) != -1) {
        System.out.print((char)c);
    }
Run Code Online (Sandbox Code Playgroud)

java

12
推荐指数
2
解决办法
6626
查看次数

压缩包含子文件夹的文件夹

public static void main(String argv[]) {
    try {
        String date = new java.text.SimpleDateFormat("MM-dd-yyyy")
                .format(new java.util.Date());
        File inFolder = new File("Output/" + date + "_4D");
        File outFolder = new File("Output/" + date + "_4D" + ".zip");
        ZipOutputStream out = new ZipOutputStream(new BufferedOutputStream(
                new FileOutputStream(outFolder)));
        BufferedInputStream in = null;
        byte[] data = new byte[1000];
        String files[] = inFolder.list();
        for (int i = 0; i < files.length; i++) {
            in = new BufferedInputStream(new FileInputStream(
                    inFolder.getPath() + "/" + files[i]), 1000);
            out.putNextEntry(new ZipEntry(files[i]));
            int …
Run Code Online (Sandbox Code Playgroud)

java zip

11
推荐指数
3
解决办法
2万
查看次数

在Java程序中使用Resultset

Resultset rs=stmt.executeQuery("select count(*) from feedsca group by score order by score");
Run Code Online (Sandbox Code Playgroud)

使用上面的上述java代码,我从名为feedsCA的表中检索行数.

虽然试图检索使用rs.getInt计数(1),rs.getInt(2),rs.getInt(3),I结束与一个错误如下说

Exception in thread "main" com.microsoft.sqlserver.jdbc.SQLServerException: The result set has no current row.
    at com.microsoft.sqlserver.jdbc.SQLServerException.makeFromDriverError(Unknown Source)
    at com.microsoft.sqlserver.jdbc.SQLServerResultSet.verifyResultSetHasCurrentRow(Unknown Source)
    at com.microsoft.sqlserver.jdbc.SQLServerResultSet.getterGetColumn(Unknown Source)
    at com.microsoft.sqlserver.jdbc.SQLServerResultSet.getInt(Unknown Source)
    at SimpleMail.main(SimpleMail.java:151)
Run Code Online (Sandbox Code Playgroud)

更新:

上述例外已经解决.

但我得到以下异常,我不知道原因.请指教.

Exception in thread "main" com.microsoft.sqlserver.jdbc.SQLServerException: The index 2 is out of range.
    at com.microsoft.sqlserver.jdbc.SQLServerException.makeFromDriverError(Unknown Source)
    at com.microsoft.sqlserver.jdbc.SQLServerResultSet.verifyValidColumnIndex(Unknown Source)
    at com.microsoft.sqlserver.jdbc.SQLServerResultSet.getterGetColumn(Unknown Source)
    at com.microsoft.sqlserver.jdbc.SQLServerResultSet.getInt(Unknown Source)
    at SimpleMail.main(SimpleMail.java:152)
Run Code Online (Sandbox Code Playgroud)

这就是我更新程序的方式.找到一个合乎逻辑的方法,因为我可以理解,下面的循环将无法按要求工作.

rs=stmt.executeQuery("select count(*) from feedsca group by score order by score");
while(rs.next()){ …
Run Code Online (Sandbox Code Playgroud)

java jdbc resultset

8
推荐指数
2
解决办法
2万
查看次数

必须导入哪些包?

import java.io.*;
import java.net.URL;
import java.net.URLConnection;
import java.sql.*;  
public class linksfind{
public static void main(){
    String html = "http://www.apple.com/pr/";
    Document document = Jsoup.parse(html); // Can also take an URL.
    for (Element element : document.getElementsByTag("a")) {
        System.out.println(element.attr("href"));
}
}
}
Run Code Online (Sandbox Code Playgroud)

伙计们,在上面的程序中,在执行时我发现了这些错误.怎么解决?我已经在我的文件夹位置下载了Jsoup.jar文件.我还该怎么办?

linksfind.java:8: cannot find symbol
symbol  : class Document
location: class linksfind
    Document document = Jsoup.parse(html); // Can also take a
    ^
linksfind.java:8: cannot find symbol
symbol  : variable Jsoup
location: class linksfind
    Document document = Jsoup.parse(html); // Can also take …
Run Code Online (Sandbox Code Playgroud)

java jsoup

4
推荐指数
1
解决办法
8523
查看次数

java.lang.NoClassDefFoundError:org/apache/commons/lang/Validate

为什么会发生以下情况?如何解决?

Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/commons/lang/Validate
    at org.jsoup.DataUtil.load(DataUtil.java:47)
    at org.jsoup.Jsoup.parse(Jsoup.java:57)
    at linksfind.main(linksfind.java:12)
Caused by: java.lang.ClassNotFoundException: org.apache.commons.lang.Validate
    at java.net.URLClassLoader$1.run(Unknown Source)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    ... 3 more
Run Code Online (Sandbox Code Playgroud)

java

4
推荐指数
1
解决办法
4万
查看次数

如何在JSP文件中以表格格式显示列表内容?

在Action.java文件中,我使用以下代码.

request.setAttribute("TAREWEIGHT", tareWeightList);
    request.setAttribute("BARCODE", barcodeList);
return (mapping.findForward(target));
Run Code Online (Sandbox Code Playgroud)

tareWeightList和barcodeList实际上只包含很少的值.将列表值设置为属性后,java文件将内容转发到JSP文件.

在JSP文件中,我可以使用下面的行获取内容,

<%=request.getAttribute("TAREWEIGHT")%>
<%=request.getAttribute("BARCODE") %>
Run Code Online (Sandbox Code Playgroud)

我的要求是该列表的内容应以表格格式显示.

第一列中的条形码值及其在第二列中的相应Tareweight值.

建议我在JSP文件中编写代码,以便以列表格式显示内容.

java jsp

4
推荐指数
1
解决办法
6万
查看次数

如何创建java程序来编译和运行java程序列表

如何为java程序构建代码以编译和执行java程序列表,而不是使用.bat文件.

java

3
推荐指数
1
解决办法
431
查看次数

如何找到执行的SQL查询没有返回任何内容?

import java.net.URL;
import java.net.URLConnection;
import java.sql.*;
public class searchlink{
public static void main(String args[]) throws Exception {
    //String link="http://hosted.ap.org";
    Connection con=null;
    Statement stmt=null;
    Statement stmtR=null;
    if(con==null){
            SQLConnection.setURL("jdbc:sqlserver://192.168.2.53\\SQL2005;user=sa;password=365media;DatabaseName=LN_ADWEEK");
            con=SQLConnection.getNewConnection();
            stmt=con.createStatement();
            stmtR=con.createStatement();
    }
    ResultSet rs;
    rs=stmt.executeQuery("select url from urls where url='http://www.topix.com/rty/elyria-oh'");
    while(rs.next()){
    String mem=rs.getString(1);
    System.out.println("Result is "+mem);}
}
}
Run Code Online (Sandbox Code Playgroud)

如果查询返回一行,上面的程序将打印输出.如果查询未返回任何内容,程序将停止而不打印任何内容.

而不是在没有打印任何东西的情况下停止它,我希望程序识别出查询没有返回任何内容并打印输出,如下所示"SQL查询执行后没有返回任何内容".

如何识别使用某些方法或变量来执行查询而不返回任何行?

java jdbc

3
推荐指数
2
解决办法
2万
查看次数

FTP上传错误"553无法创建文件"

import org.apache.commons.net.ftp.FTPClient;

import org.apache.commons.net.ftp.FTPReply;

import org.apache.commons.net.ftp.FTPFile;
import java.io.*;

public class FTPUpload{


public static boolean uploadfile(String server,String username,String Password,String source_file_path,String dest_dir){

FTPClient ftp=new FTPClient();

try {

 int reply;


 ftp.connect(server);

   ftp.login(username, Password);
 System.out.println("Connected to " + server + ".");

 System.out.print(ftp.getReplyString());


 reply = ftp.getReplyCode();


 if(!FTPReply.isPositiveCompletion(reply)) {

ftp.disconnect();

System.err.println("FTP server refused connection.");

return false;

 }

 System.out.println("FTP server connected.");

                    InputStream input= new FileInputStream(source_file_path);


 ftp.storeFile(dest_dir, input);

  System.out.println( ftp.getReplyString() );

                    input.close();

                    ftp.logout();

 } catch(Exception e) {

                    System.out.println("err");

   e.printStackTrace();

                    return false;

  } finally {

   if(ftp.isConnected()) {

    try { …
Run Code Online (Sandbox Code Playgroud)

java ftp ftp-client

3
推荐指数
1
解决办法
9779
查看次数

标签 统计

java ×10

jdbc ×2

jsp ×2

ftp ×1

ftp-client ×1

java-home ×1

jsoup ×1

resultset ×1

tomcat ×1

tomcat5.5 ×1

zip ×1