小编Man*_*shS的帖子

Node.js __dirname未定义

我的目录看起来像这样:

/config.json,/server.js,/staticFiles/welcome.html

运行server.js会出错:

app.use(express.static(_dirname +"/ staticFiles")); ^ ReferenceError:未定义_dirname

我的Server.js:

//------------Server-------------

var fs = require("fs");
var config = JSON.parse(fs.readFileSync("./config.json"));

 console.log("Server UP and running.."); 

 var host = config.host;
 var port = config.port;
 var express = require("express");

 var app = express.createServer();



 //---------Application----------------

app.use(app.router);
 app.use(express.static(_dirname + "/staticFiles"));

app.get("/", function(request,response){

response.send("<h1>"/" of TrimServer</h1>");

 });

app.listen(port,host); 
console.log("Listening on Port -->",port);


 //--------------End-------------------
Run Code Online (Sandbox Code Playgroud)

javascript node.js

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

给定正数的所有数字的总和

方法返回应该如果输入一个数字,假设345,那么输出应该是3 + 4 + 5 = 12 - > 1 + 2 = 3.我在这里做错了什么?

public class DigitSum
 {
    int  Sum=0;

    public int compute( int MethParam )
    {
        int rem = MethParam%10; 
        Sum+=rem;        

        MethParam = MethParam/10; 
        if(MethParam>10)
            compute(MethParam);

        return Sum+MethParam;  
    }

  public static void main(String[] args)
  {
    DigitSum ds  = new DigitSum();
    System.out.println(ds.compute(435));
  }
}
Run Code Online (Sandbox Code Playgroud)

java algorithm

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

为什么私有,静态,受保护的访问修改器不与类一起使用?

为什么相同,可以用于内部类?

public class Hello {
    class inner{ // this class can use any modifier
    }
}               
Run Code Online (Sandbox Code Playgroud)

java

-1
推荐指数
1
解决办法
1553
查看次数

返回Java异常

public class TestException {

    int m1() {

        try {
            int i = 10, j = 0;
            System.out.println("s1");
            i = i / j;
            return 11;
        } catch (Exception e) {
            System.out.println("s2");
        } finally {
            System.out.println("s3");
        }

        System.out.println("s4");
        return 2222;
    }

    public static void main(String[] args) {
        System.out.println(new TestException().m1());
    }
}
Run Code Online (Sandbox Code Playgroud)

O/P: -

s1
s2
s3
s4
2222
Run Code Online (Sandbox Code Playgroud)

s3以前为什么s4

finally在方法返回之前不调用?

我在这里错过了什么?

java exception

-2
推荐指数
1
解决办法
121
查看次数

标签 统计

java ×3

algorithm ×1

exception ×1

javascript ×1

node.js ×1