在我的asp.net Web应用程序中,我必须在App_Data文件夹中读取somef文件,但我不知道设置路径的热点.
如果在网络表单中,我知道我可以使用:
Sever.mapPath("~/App_Data");
Run Code Online (Sandbox Code Playgroud)
但是现在我想要在App_code中的.cs文件中检索路径.
所以那里没有HttpServer上下文.
任何的想法?
假设我有一个POJO User
,我添加了一些静态方法来执行CRUD操作:
public class User {
private String name;
private int age;
// getter and setter omitted
//
public static void add(User user) {
// add person
}
public static int delete(Object id) {
// delete person
return 1;
}
}
Run Code Online (Sandbox Code Playgroud)
因为我有像User这样的其他实体,所以我想把这个add
和delete
方法抽象化,就像这样;
public class?interface Entity<T>{
static add(T t);
static delete(Object id);
}
public class User extends Entity<User>{
@override
static add(User user){
// add ...
}
....
}
Run Code Online (Sandbox Code Playgroud)
这可能吗?
我必须为很多表添加主键,并且我从stackoverflow获得了以下脚本(对于一个表):
ALTER TABLE table1 ADD ID NUMBER(12);
CREATE SEQUENCE table1Seq START WITH 1;
UPDATE table1 SET table1ID = table1Seq.NEXTVAL;
ALTER TABLE table1 ADD PRIMARY KEY (ID);
CREATE OR REPLACE TRIGGER table1PKSet
BEFORE INSERT ON table1
FOR EACH ROW
BEGIN
:NEW.ID := table1Seq.NEXTVAL;
END;
/
Run Code Online (Sandbox Code Playgroud)
但是现在我已经为用户的所有表执行了相同的操作.
所以我想知道我是否可以使用pl/sql循环用户的所有表,并执行上述操作?
在我的页面中,我导入了第三部分的CSS样式,但是我想覆盖一些属性.
例如,在第三方风格中有这样的规则:
.control{
width:20em;
}
Run Code Online (Sandbox Code Playgroud)
现在我想删除width属性.
然后我试着.control
在我自己的CSS中重新定义:
.control{
width:"auto";
}
Run Code Online (Sandbox Code Playgroud)
但似乎这不起作用.
问题是什么?怎么解决?
更新:
我忘了,第三方样式是由第三方javascript库添加的,所以我不确定它在页面内的位置,
然后我不知道在添加的样式之后在哪里放置我的风格.
我是NodeJS的新手,我正在做一个例子:
function test(req,res){
var path = urls[Math.floor(Math.random()*urls.length)];
console.log("try to redirect to:"+path);
http.get(path,function(res_server){
//how to send the data from res_server to res
});
}
Run Code Online (Sandbox Code Playgroud)
这urls
是一个网址数组.
我想知道如何将数据从res_server
原始客户端发送到原始客户端response
?
顺便说一句,网址可能http
或https
.
更新
var urls=["url1","url2","url3"];
var path = urls[Math.floor(Math.random()*urls.length)]; // find an random item from the array
Run Code Online (Sandbox Code Playgroud)
更新:2
好的,这是完整的简单测试脚本:
var http=require("http");
http.createServer(function(req, res1) {
var url = 'http://www.google.com.hk/images/srpr/logo11w.png';
var hp=require("http");
hp.get(url, function(res2) {
res2.pipe(res1);
});
}).listen(3000);
Run Code Online (Sandbox Code Playgroud)
它有效,但如果你换http://www.google.com.hk/...logo..png
到https:/www.google.....png
它会抛出错误:
http.js:1840
throw new Error('Protocol:' + …
Run Code Online (Sandbox Code Playgroud) 嗨:在我的网站上,我发现他们的网址非常简单:
http://example.com/questions/4486620/randomaccessfile-probelm
通常网址应该像:
http://example.com/questions?xx=4486620&title=randomaccessfile-probelm
也就是说,url中没有"&"组合的请求参数.
他们是怎么做到的?有框架吗?
更新: 我的应用程序在tomcat下运行.
码:
1)
function Person(name,age){
this.name=name;
this.age=age;
}
var p=new Person('stack',100);
console.dir(p);
console.info(p.name);//'stack'.
Run Code Online (Sandbox Code Playgroud)
但我想知道为什么我可以创建一个新人使用:
var p2=new Person(); //no error
Run Code Online (Sandbox Code Playgroud)
没有像这样的构造函数:
function Person(){}
Run Code Online (Sandbox Code Playgroud)
为什么?
2)
function Person(name,age){
var _name,_age;
this._name=name;
this._age=age;
}
var p=new Person('stack',100);
console.dir(p);
Run Code Online (Sandbox Code Playgroud)
这与1)的方式有什么区别?
我在我们的项目中使用原型1.4,我曾经以这种方式创建类:
1)方式1
var Person=Class.create();
Person.prototype={
initialize:function(name,age){
this._check(name,age);
this.name=name;
this.age=age;
},
say:function(){
console.log(this.name+','+this.age);
}
_check:function(name,age){
if(typeof(name)!='string' || typeof(age)!='number')
throw new Error("Bad format...");
}
}
Run Code Online (Sandbox Code Playgroud)
但是,在上面的代码中,Person"_check"的方法可以在外部调用,这不是我期望的.
在我以前的帖子中,感谢'TJ Crowder',他告诉我一个解决方案,使该方法完全私密:
2)方式2
var Person=(function(){
var person_real=Class.create();
person_real.prototype={
initialize:function(name,age){
_check(name,age);
this.name=name;
this.age=age;
},
say:function(){
console.log(this.name+','+this.age);
}
}
//some private method
function _check(name,age){
//....the check code here
}
return person_real;
})();
Run Code Online (Sandbox Code Playgroud)
现在,"_ check"不能暴露在外面.
但我现在感到困惑的是,这种方式会导致性能问题还是最好的实践?
由于我们创建类(蓝图)的原因之一是减少重复代码,可以在任何地方多次重复使用.
现在看看"Manner1":
我们创建一个Class"Person",然后我们将所有实例方法放到Person类的原型对象中.然后每次我们打电话给
var obj=new Person('xx',21);
Run Code Online (Sandbox Code Playgroud)
对象"obj"将拥有Person.prototype中的方法."obj"本身并没有任何代码.
但是在"Manner2"中:每次我们打电话:
var obj=new Person('xx',21);
Run Code Online (Sandbox Code Playgroud)
将创建一个新蓝图,每次也会创建诸如"_check"之类的私有方法.是浪费记忆吗?
注意:也许我错了.但我真的很困惑.任何人都可以给我解释一下吗?
我有一些数字值,我想确保它们最多可以容纳2位数.
例如:
11.1233 --> 11.12
11.1 --> 11.1
123 --> 123
Run Code Online (Sandbox Code Playgroud)
我想过要用
String.format("%.2f",11.1233)
Run Code Online (Sandbox Code Playgroud)
这适用于超过2位数的数字,但它会增加额外的数字,0
例如,它将导致以下结果:
11.1 --> 11.10
123 --> 123.00
Run Code Online (Sandbox Code Playgroud)
虽然我不需要额外的0
.
还有其他选择吗?
我有一个 JavaEE 应用程序,需要在运行时配置一些特定的系统属性。
在开发阶段,我们设置属性以.pom.xml
使其工作:
<plugin>
<groupId>org.apache.tomcat.maven</groupId>
<artifactId>tomcat7-maven-plugin</artifactId>
<version>2.2</version>
<configuration>
<systemProperties>
<xxx>true</xxx>
</systemProperties>
</configuration>
</plugin>
Run Code Online (Sandbox Code Playgroud)
但是我想知道如果我们将应用程序部署在生产环境中怎么样?
我虽然在 servlet 初始化期间设置了该属性,但似乎一旦 jvm 运行我就无法修改系统属性(来自这篇文章):
Hotspot Java 实现的 JVM 内存参数只能在 JVM 启动时通过命令行选项进行设置。在 JVM 启动之前或之后在系统属性中设置它们将不会产生任何效果。
我尝试在web.xml
(此处)中设置属性:
<env-entry>
<env-entry-name>xx</env-entry-name>
<env-entry-type>java.lang.String</env-entry-type>
<env-entry-value>xx</env-entry-value>
</env-entry>
Run Code Online (Sandbox Code Playgroud)
但好像并没有什么影响。
然后我就想怎么解决呢?
顺便说一句,在生产环境中,我们可能会在共享 tomcat 下运行多个应用程序,因此我们更愿意仅在应用程序上下文下设置属性。
假设我有一个数组:
var ay=[0,1,2,3,4,5,6,7,8,9];
Run Code Online (Sandbox Code Playgroud)
现在我想得到两个数组:
var ay1=[0,2,4,6,8];
var ay2=[1,3,5,7,9];
Run Code Online (Sandbox Code Playgroud)
有效的方法是什么?
更新:
我知道简单的循环和模运算符方法(如上所述elclanrs
),如下所示:
var ay1=[],ay2=[];
for(var i=0,len=ay.length;i++){
if(i%2==0){
ay2.push(ay[i]);
} else
ay1.push(ay[i]);
}
Run Code Online (Sandbox Code Playgroud)
但我只是想知道是否还有其他有效或酷的方式我还不知道.
这就是为什么我问这个简单的问题.我不是问怎么做,我问如果可能的话怎么做得更好!
所以我认为这篇文章不值得投票.
代码:
g = function () {
H = 3
return H + H
}
f = function () {
? = 2
return ? + H
}
// 3 + 3 = 6
alert(g())
// 2 + 2 = 5
alert(f())
Run Code Online (Sandbox Code Playgroud)
现场演示:http://jsfiddle.net/qhRJY/light/
虽然输出是6
和5
.
它很奇怪.
然后我尝试改变值H
,结果仍然是意料之外的.
这里的魔力是什么?