我有一段JavaScript代码创建(使用D3.js)svg
包含图表的元素.我想基于来自使用AJAX的Web服务的新数据更新图表,问题是每次我点击更新按钮时,它都会生成一个新的svg
,所以我想删除旧的或更新其内容.
这是JavaScript函数的一个片段,我在其中创建svg
:
var svg = d3.select("body")
.append("svg")
.attr("width", w)
.attr("height", h);
Run Code Online (Sandbox Code Playgroud)
如何删除旧svg
元素或至少替换其内容?
是否可以在特定时间调用java中的方法?例如,我有一段这样的代码:
class Test{
....
// parameters
....
public static void main(String args[]) {
// here i want to call foo at : 2012-07-06 13:05:45 for instance
foo();
}
}
Run Code Online (Sandbox Code Playgroud)
如何在java中完成这项工作?
我有以下资源(使用Spring 4.05.RELEASE实现),它接受一个文件和一个JSON对象:
(PS activityTemplate是一个可序列化的实体类)
...
@RequestMapping(value="/create", method=RequestMethod.POST)
public @ResponseBody ActivityTemplate createActivityTemplate(
@RequestPart ActivityTemplate activityTemplate, @RequestPart MultipartFile jarFile)
{
//process the file and JSON
}
...
Run Code Online (Sandbox Code Playgroud)
这是我测试的形式:
<form method="POST" enctype="multipart/form-data"
action="http://localhost:8080/activityTemplates/create">
JSON: <input type="text" name="activityTemplate" value='/* the JSON object*/'><br />
File to upload: <input type="file" name="file">
<input type="submit" value="Upload">
</form>
Run Code Online (Sandbox Code Playgroud)
这是我得到的错误:
There was an unexpected error (type=Unsupported Media Type, status=415).
Content type 'application/octet-stream' not supported
Run Code Online (Sandbox Code Playgroud)
那么如何让资源接受JSON对象作为multipart请求的一部分,或者我应该以不同的方式发送表单?
我想生成一个随机时间戳并为其添加一个随机增量以生成第二个时间戳.那可能吗?
如果我传递随机长值来创建时间戳,并且我想随机生成该长值,那么生成此值以在2012年给出时间戳的约束是什么?
我正在使用Mongo存储库来执行CRUD操作,如下面的代码所示.尽管此代码有效,但文档和集合是在与我想要的DB不同的DB中创建的.如何显式指定要存储文档的数据库名称.
POJO课程:
@Document(collection = "actors")
public class Actor
{
@Id
private String id;
...
//constructor
//setters & getters
}
Run Code Online (Sandbox Code Playgroud)
存储库:
public interface ActorRepository extends MongoRepository<Actor, String>
{
public Actor findByFNameAndLName(String fName, String lName);
public Actor findByFName (String fName);
public Actor findByLName(String lName);
}
Run Code Online (Sandbox Code Playgroud)
使用存储库的服务:
@Service
public class ActorService
{
@Autowired
private ActorRepository actorRepository;
public Actor insert(Actor a)
{
a.setId(null);
return actorRepository.save(a);
}
}
Run Code Online (Sandbox Code Playgroud)
我从REST控制器类访问该服务:
@RestController
public class Controllers
{
private static final Logger logger = Logger.getLogger(Controllers.class);
private static final ApplicationContext …
Run Code Online (Sandbox Code Playgroud) 首先,我有一个概念性的问题,"分布式"这个词是否只意味着应用程序在多台机器上运行?或者还有其他方法可以将应用程序视为分布式(例如,如果有许多独立的模块在同一台机器上进行交互,这是分布式的吗?).
其次,我想建立一个执行四种类型任务的系统,会有多个客户,每个客户都会定期运行每种类型的许多任务.例如:customer1今天将有task_type1,两天后会有task_type2,依此类推,可能会有customer2同时执行task_type1,如customer1的task_type1.即需要并发.执行任务的配置将存储在DB中,这些任务的结果也将存储在DB中.客户将使用Web浏览器(html页面)中的系统与系统交互(基本上,配置任务并查看结果).我想过使用一个休息webservice(使用JAX-RS),其中html页面将与后端通信并在后端使用线程进行并发执行.问题:
2.如果我的方法很好,我是否需要使用像JSP这样的脚本语言,或者我可以直接将html表单提交给其他URL并获得结果(例如使用JSON)?
很抱歉有很多问题,但我对此感到很困惑.
java multithreading web-services client-server distributed-computing
我试图使用192.168.0.6:8080(A的IP)从局域网上的另一台机器(B)访问一个Web应用程序(在我的机器(A)上的jetty8中部署),但它无法正常工作.虽然我可以通过使用192.168.0.5(B的IP)从A访问机器B上AppServ上托管的应用程序.
我可以在机器A上的localhost:8080上正常访问该应用程序.
我可以确保没有网络问题,但由于某种原因无法通过网络访问码头.是否有任何特定配置可通过LAN访问?
我的应用程序是Maven项目,我从eclipse运行它,设置在web.xml和pom.xml中.
我有一个用java实现的Web服务项目,它还包含jsp页面.我在我的机器上将它部署在jetty 8.1.5上并且它正常工作.但是,当我使用jetty 8.1.3部署在Windows Server 2003上时,它会出现以下异常:
org.apache.jasper.el.ELContextImpl cannot be cast to org.apache.jasper.runtime.ELContextImpl
Run Code Online (Sandbox Code Playgroud)
这是完整的痕迹:
java.lang.ClassCastException: org.apache.jasper.el.ELContextImpl cannot be cast to org.apache.jasper.runtime.ELContextImpl
at org.apache.jasper.runtime.PageContextImpl.evaluateExpression(PageContextImpl.java:1002)
at org.apache.jsp.home.index_jsp._jspService(org.apache.jsp.home.index_jsp:52)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:111)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:848)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:403)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:492)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:378)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:848)
at org.eclipse.jetty.servlet.ServletHolder.handle(ServletHolder.java:598)
at org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:486)
at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:119)
at org.eclipse.jetty.security.SecurityHandler.handle(SecurityHandler.java:542)
at org.eclipse.jetty.server.session.SessionHandler.doHandle(SessionHandler.java:233)
at org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:1065)
at org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:413)
at org.eclipse.jetty.server.session.SessionHandler.doScope(SessionHandler.java:192)
at org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:999)
at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:117)
at org.eclipse.jetty.server.Dispatcher.forward(Dispatcher.java:271)
at org.eclipse.jetty.server.Dispatcher.forward(Dispatcher.java:98)
at org.eclipse.jetty.servlet.DefaultServlet.doGet(DefaultServlet.java:557)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:735)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:848)
at org.eclipse.jetty.servlet.ServletHolder.handle(ServletHolder.java:598)
at org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:486)
at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:119)
at org.eclipse.jetty.security.SecurityHandler.handle(SecurityHandler.java:499)
at org.eclipse.jetty.server.session.SessionHandler.doHandle(SessionHandler.java:233)
at org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:1065)
at org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:413)
at …
Run Code Online (Sandbox Code Playgroud) 我一直在寻找使用apache common math 3.0为特定数据集生成垃圾箱(通过指定低频段,高频段和所需的频段数).我看过频率http://commons.apache.org/math/apidocs/org/apache/commons/math3/stat/Frequency.html 但它没有给我我想要的东西..我想要一个给我的方法间隔中值的频率(例如:0到5之间有多少个值).有什么建议或想法吗?
我希望o make thread在特定的时间执行(例如:2012-07-11 13:12:24和2012-07-11 15:23:45)
我查了一下ScheduledExecutorService
,但它仅支持从第一次运行一定时间后执行,我没有任何固定的时间段,而不是我有时间从数据库上执行任务.
在一个不同的问题,前一个问题在这里,TimerTask的是解决方案,但obviuosly我不能让一个线程TimerTask
作为Runnable
与TimerTask
两者都有方法run
需要被实现.这里的问题是,如果我使线程扩展TimerTask
并有一个实现run()
,那会有效吗?如果没有,那么我怎么可能做我想做的事情?