我<error-page>在web.xml中使用元素来指定用户遇到某个错误时的友好错误页面,例如代码为404的错误:
<error-page>
<error-code>404</error-code>
<location>/Error404.html</location>
</error-page>
Run Code Online (Sandbox Code Playgroud)
但是,我希望如果用户不符合指定的任何错误代码<error-page>,他或她应该看到默认错误页面.如何使用web.xml中的元素执行此操作?
我正在阅读一些Java文本并获得以下代码:
int[] a = {4,4};
int b = 1;
a[b] = b = 0;
Run Code Online (Sandbox Code Playgroud)
在文中,作者没有给出明确的解释,最后一行的效果是: a[1] = 0;
我不太清楚我理解:评估是如何发生的?
我有以下程序:
int main(int argc, char *argv[])
{
int a, b;
char c1, c2;
printf("Enter something: ");
scanf("%d",&a); // line 1
printf("Enter other something: ");
scanf("%d", &b); // line 2
printf("Enter a char: ");
scanf("%c",&c1); // line 3
printf("Enter another char: ");
scanf("%c", &c2); // line 4
printf("Done"); // line 5
system("PAUSE");
return 0;
}
Run Code Online (Sandbox Code Playgroud)
正如我在C书中读到的那样,作者说scanf()在缓冲区中留下了一个新的行字符,因此,程序不会在第4行停止供用户输入数据,而是将新行字符存储在c2中并移至第5行.
是对的吗?
但是,这只发生在char数据类型中吗?因为我没有int在第1,2,3行中看到数据类型的这个问题.是不是?
我有以下程序:
int main(int argc, char *argv[])
{
char ch1, ch2;
printf("Input the first character:"); // Line 1
scanf("%c", &ch1);
printf("Input the second character:"); // Line 2
ch2 = getchar();
printf("ch1=%c, ASCII code = %d\n", ch1, ch1);
printf("ch2=%c, ASCII code = %d\n", ch2, ch2);
system("PAUSE");
return 0;
}
Run Code Online (Sandbox Code Playgroud)
正如上面代码的作者所解释的那样:程序将无法正常工作,因为在第1行,当用户按下Enter时,它将在输入缓冲区中留下2个字符:Enter key (ASCII code 13)和\n (ASCII code 10).因此,在第2行,它将读取\n并且不会等待用户输入字符.
好的,我明白了.但我的第一个问题是:为什么第二个getchar()(ch2 = getchar();)不读取Enter key (13)而不是\n字符?
接下来,作者提出了两种解决此类问题的方法:
使用 fflush()
写一个这样的函数:
void
clear …Run Code Online (Sandbox Code Playgroud)我不知道为什么在Java或其他语言中浮点值之后放置f或F?例如,
float fVariable = 12.3f;
Run Code Online (Sandbox Code Playgroud)
除了表明这是浮点值以外的任何其他功能?
在C编程语言中,unsigned int仅用于存储正值.但是,当我运行以下代码时:
unsigned int x = -12;
printf("%d", x);
Run Code Online (Sandbox Code Playgroud)
输出仍为-12.我认为应该打印出来:12,还是我误解了什么?
我正在阅读一些Java文本,文本说我们只能为类和接口应用public或default访问修饰符.因此,如果我们声明:它是一个编译错误:
private class A {}
Run Code Online (Sandbox Code Playgroud)
要么
protected class A{}
Run Code Online (Sandbox Code Playgroud)
我只是好奇为什么类或接口无法接收private或protected访问修饰符?
我正在读一本C书,谈论浮点范围,作者给出了表:
Type Smallest Positive Value Largest value Precision
==== ======================= ============= =========
float 1.17549 x 10^-38 3.40282 x 10^38 6 digits
double 2.22507 x 10^-308 1.79769 x 10^308 15 digits
Run Code Online (Sandbox Code Playgroud)
我不知道最小正值和最大值列中的数字来自哪里.
我正在使用Jedis池来管理与Redis服务器的连接.我的示例代码如下:
public Set<String> getTopArticleList(int start, int end) {
Set<String> list = null;
Jedis j = JedisFactory.getInstance().getJedisPool().getResource();
Pipeline pipe = j.pipelined();
try {
// do stuff with redis
pipe.sync();
} catch (JedisConnectionException jex) {
JedisFactory.getInstance().getJedisPool().returnBrokenResource(j);
} finally {
JedisFactory.getInstance().getJedisPool().returnResource(j);
}
return list;
}
Run Code Online (Sandbox Code Playgroud)
用于创建和检索Jedis池的代码:
class JedisFactory {
private static JedisPool jedisPool;
public JedisFactory() {
JedisPoolConfig poolConfig = new JedisPoolConfig();
jedisPool = new JedisPool(
poolConfig,
RedisDBConfig.HOST,
RedisDBConfig.PORT,
RedisDBConfig.TIMEOUT,
RedisDBConfig.PASSWORD
);
}
public JedisPool getJedisPool() {
return jedisPool;
}
public static JedisFactory getInstance() …Run Code Online (Sandbox Code Playgroud) 在Java中,如果特定的代码行导致程序崩溃,则捕获异常并继续执行程序.
但是,在C++中,如果我有一段导致程序崩溃的代码,例如:
try
{
int x = 6;
int *p = NULL;
p = reinterpret_cast<int*>(x);
*p = 10; // the program crashed here
cout << "x = " << *p << endl;
}
catch(const char* Message)
{
cout << "There is an run-time error";
}
Run Code Online (Sandbox Code Playgroud)
然后程序仍然崩溃,并且没有捕获异常.
那么C++中的异常处理有什么意义呢?我误会了什么吗?