关于我今天看过的FOR循环,我有一个小问题.它看起来像这样:
for (double i = 0.0; i < 1.0; i += 0.1) {
for (double j = i; j < 1.0; j += 0.1) {
double k = i + j;
if ((k % 1) == 0) {
System.out.println(i + " + " + j + " = " + k);
}
}
}
Run Code Online (Sandbox Code Playgroud)
它应该输出0到1之间的两个数字的总和(递增0.1),它们等于整数.但是,由于某种原因,它没有显示0.1 + 0.9 = 1.0的总和.我的猜测可能是因为双格式的数字表示不正确(即0.3 + 0.1不是0.4,而是像0,399999999).
任何人都可以确认这是真正的问题,并建议如何纠正它?任何帮助都非常赞赏!
我需要从另一个类文件中访问一个变量(一个int).我该怎么做?它是一个公共int,我需要获取int值并将其放入一个文件中.
我正在尝试为GwtUpload库实现Basic示例,如此处所示.
在我的服务器代码中,我收到以下错误:
异常java.lang.ClassCastException:org.apache.commons.fileupload.disk.DiskFileItem无法强制转换为org.apache.commons.fileupload.FileItem
我无法弄清楚为什么会这样.DiskFileItem是FileItem的子类,应该可以工作.我已经在调试器中逐步完成并确认这两个类是他们看起来的类,但是赋值失败了.
更奇怪的是,当我尝试在监视窗口中调用FileItem方法时,我没有问题,但是如果我尝试在代码中访问它们,我就会收到错误.
这是我的Servlet代码:
public class GwtUploadServlet extends UploadAction
{
private static final long serialVersionUID = 1L;
/**
* Maintain a list with received files and their content types.
*/
Hashtable<String, String> receivedContentTypes = new Hashtable<String, String>();
/**
* Maintain a list with received files.
*/
Hashtable<String, File> receivedFiles = new Hashtable<String, File>();
/**
* Override executeAction to save the received files in a custom place and
* delete this items from session.
*/
@Override
public …Run Code Online (Sandbox Code Playgroud) import java.util.*;
public Class C
{
final Vector v;
C()
{
v=new Vector();
}
C(int i)
{
//Here, it is an error. v might not have been initialized.
}
public void someMethod()
{
System.out.println(v.isEmpty());
}
public static void main(String[] args)
{
C c=new C();
c.someMethod();
}
}
Run Code Online (Sandbox Code Playgroud)
上面的代码是编译时错误.我知道,但它说(在NetBeans中)变量v应该被初始化.当我在重载的构造函数中初始化它时,它修复了问题并打印"true".我的问题是为什么我应该在重载版本的构造函数中再次初始化它.(我在默认构造函数中初始化了一次)并且我甚至没有使用重载版本.为什么?
我得到这个例外:
Exception in thread "AWT-EventQueue-0" java.lang.OutOfMemoryError: Java heap space
at java.util.Arrays.copyOf(Arrays.java:2882)
at java.lang.AbstractStringBuilder.expandCapacity(AbstractStringBuilder.java:100)
at java.lang.AbstractStringBuilder.append(AbstractStringBuilder.java:390)
at java.lang.StringBuilder.append(StringBuilder.java:119)
at java.util.AbstractMap.toString(AbstractMap.java:493)
at org.hibernate.pretty.Printer.toString(Printer.java:59)
at org.hibernate.pretty.Printer.toString(Printer.java:90)
at org.hibernate.event.def.AbstractFlushingEventListener.flushEverythingToExecutions(AbstractFlushingEventListener.java:97)
at org.hibernate.event.def.DefaultAutoFlushEventListener.onAutoFlush(DefaultAutoFlushEventListener.java:35)
at org.hibernate.impl.SessionImpl.autoFlushIfRequired(SessionImpl.java:969)
at org.hibernate.impl.SessionImpl.list(SessionImpl.java:1114)
at org.hibernate.impl.QueryImpl.list(QueryImpl.java:79)
Run Code Online (Sandbox Code Playgroud)
在此代码:
Query query = null;
Transaction tx= session.beginTransaction();
if (allRadio.isSelected()) {
query = session.createQuery("select d from Document as d, d.msg as m, m.senderreceivers as s where m.isDraft=0 and d.isMain=1 and s.organization.shortName like '" + search + "' and s.role=0");
} else if (periodRadio.isSelected()) {
query = session.createQuery("select …Run Code Online (Sandbox Code Playgroud) 我是新来的春天.我正在尝试使用spring mvc来构建一个小型Web.当我启动项目时,我得到:
org.apache.jasper.JasperException: Unable to compile class for JSP:
An error occurred at line: 22 in the generated java file
The method getJspApplicationContext(ServletContext) is undefined for the type JspFactory
Stacktrace:
at org.apache.jasper.compiler.DefaultErrorHandler.javacError(DefaultErrorHandler.java:92)
at org.apache.jasper.compiler.ErrorDispatcher.javacError(ErrorDispatcher.java:330)
at org.apache.jasper.compiler.JDTCompiler.generateClass(JDTCompiler.java:439)
at org.apache.jasper.compiler.Compiler.compile(Compiler.java:349)
at org.apache.jasper.compiler.Compiler.compile(Compiler.java:327)
at org.apache.jasper.compiler.Compiler.compile(Compiler.java:314)
at org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:589)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:317)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:313)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:260)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:298)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:852)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:588)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489)
at java.lang.Thread.run(Thread.java:662)
Run Code Online (Sandbox Code Playgroud)
Http状态是500,但我的index.jsp只有
<html>
<body>
<h2>Hello …Run Code Online (Sandbox Code Playgroud) 假设我有一个1,000,000个用户的列表,其唯一标识符是他们的用户名字符串.因此,为了比较两个用户对象,我只是重写compareTo()方法,比较用户名成员.
给定一个用户名字符串,我希望User从列表中找到该对象.在一般情况下,这是最快的方法.
我猜测HashMap,将用户名映射到User对象,但我想知道是否还有其他一些我不知道哪些会更好.
我有一个Java servlet,在发送最终响应(这是一个PDF文件)之前,我需要向HTML页面发送一些通知.
基本上我需要让用户更新我正在执行的步骤,同时为他们生成PDF.
我猜,一种方法可以设置各种属性使用HttpSession并使用JS打印.但我不知道如何在不重新加载页面的情况下动态地执行此操作.
关于如何做到这一点的任何想法?我是JSP和servlet的新手.
您好,我有一个 SPARQL 查询,它在 where 子句中包含此内容
...
optional {
?v foo:thing ?something .
$dontgetthis
?v bar:somethingelse ?otherthing .
...
}
...
Run Code Online (Sandbox Code Playgroud)
现在,我明白了大部分内容,除了一件事。我不明白$dontgetthis。这是什么意思? $dontgetthis不在查询中的其他任何地方使用。
我使用eclipse 3.2.2作为IDE.我想要maven代码来构建和部署我的Web应用程序,这是使用spring web mvc 2.0.