class a
{
static final int a =5;
static {
System.out.println("hi");
}
}
class b
{
public static void main(String[] args) {
System.out.println(a.a);
}
}
Run Code Online (Sandbox Code Playgroud)
为什么静态块不运行,输出只是
五
而如果我从类变量中删除final关键字,则执行静态块并输出
hi
5
Run Code Online (Sandbox Code Playgroud) 我有一个简单的标签,其中有一个url作为其href,当我点击它时,它会将URL附加到当前地址.
地址是www.example.com/event/
<a href="www.yahoo.com" taget="_blank">Here</a>
Run Code Online (Sandbox Code Playgroud)
当我点击它时,它将变为以下
www.example.com/event/www.yahoo.com
Run Code Online (Sandbox Code Playgroud) 将数据记录保存到数据库时,我在SQL语法中出错:
Caused by: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'option, createdBy, createdDate, updatedBy, updatedDate, description) values ('QU' at line 1
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
at java.lang.reflect.Constructor.newInstance(Unknown Source)
at com.mysql.jdbc.Util.handleNewInstance(Util.java:406)
at com.mysql.jdbc.Util.getInstance(Util.java:381)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1031)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:956)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3558)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3490)
at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1959)
at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2109)
at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2648)
at com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:2077)
at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:2362)
at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:2280)
at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:2265)
at org.hibernate.id.IdentityGenerator$GetGeneratedKeysDelegate.executeAndExtract(IdentityGenerator.java:94) …
Run Code Online (Sandbox Code Playgroud) "random".hashCode()
返回值-938285885.是否预期负值hashCode()
?
根据以下问题,有一种方法hashCode()
可以计算字符串,但是使用它,随着字符串长度的增加,值不会继续增加,最终会大于Integer.MAX_VALUE
?
在try-with-resources [autoclosable]块中使用GZipOutputStream时,我在处理完资源finish()
后是否需要显式调用?
通过谷歌搜索,在这个 SO 站点中,结果将FileUtils.listFilesAndDirs()
来自 Apache Commons IO 的方法。
但是这种方法不会递归进入子文件夹 - 我们需要递归文件列表。
我们如何使用 Commons IO 做到这一点?
PS:
一种本机方法是使用File.listFiles()
JDK 本机支持的解决方案here。
代码无效
$(document).ready(function() {
if the action is successful and returns a success message then Only{
document.getElementById("tabledataid_row").focus();
}
});
Run Code Online (Sandbox Code Playgroud)
表数据内容
<table>
<tr>
<td id="tabledataid_row"></td>
</tr>
</table>
Run Code Online (Sandbox Code Playgroud)
我希望<td>
在提交页面后将焦点放回到表格数据中.例如,在Struts操作中,提交将表单返回到屏幕顶部.我尝试使用JavaScript方法focus()
,它适用于textfield或输入类型的元素.
但是当我为<td>
元素分配一个id 然后以onload/document ready形式将其拾取然后像上面那样调用focus()时,它就不起作用了.
请注意,我已经在各个地方插入了tabindex,这个元素id有tabindex 4.所以,我不想更改tabindex以获得焦点来到id.只有可视页面以所需字段可见的方式移动.
我知道java使用UTF-16
编码.即Java用于16 bits
编码字符.所以java可以支持65536
字符.所以java可以提供国际化.
当我使用Struts2时,我看到Struts2使用的UTF-8
编码意味着它只能支持256个字符,ASCII
但Struts2仍然支持国际化.
现在我的问题是UTF-8
编码如何支持只有256个字符的国际化?
我有这个html代码:
<td style="padding:1%; " width="80%"><form:textarea name="reference" path="" placeholder="insert_word" width="100%" /></td>
Run Code Online (Sandbox Code Playgroud)
我想从 language.properties 文件中获取占位符单词,我有文件 langueage.properties:
insert_word=add your word here!
Run Code Online (Sandbox Code Playgroud)
我该如何使用<fmt:message>
标签来做到这一点?我已经在 html 代码的开头添加了这一行:
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt" %>
<fmt:setBundle basename="language" />
Run Code Online (Sandbox Code Playgroud)
当我将<fmt:message>
标签放在“值”内时,它工作正常,但在占位符内我收到一些错误:
<td style="padding:1%; " width="80%"><form:textarea name="reference" path="" placeholder=<fmt:message key="insert_word" /> width="100%" /></td>
Run Code Online (Sandbox Code Playgroud)
错误:
org.apache.jasper.JasperException: /WEB-INF/views/ContactForm.jsp (line: 188, column: 98) quote symbol expected
org.apache.jasper.compiler.DefaultErrorHandler.jspError(DefaultErrorHandler.java:42)
org.apache.jasper.compiler.ErrorDispatcher.dispatch(ErrorDispatcher.java:443)
org.apache.jasper.compiler.ErrorDispatcher.jspError(ErrorDispatcher.java:89)
org.apache.jasper.compiler.Parser.parseAttribute(Parser.java:224)
org.apache.jasper.compiler.Parser.parseAttributes(Parser.java:162)
org.apache.jasper.compiler.Parser.parseAttributes(Parser.java:153)
org.apache.jasper.compiler.Parser.parseCustomTag(Parser.java:1229)
.........
Run Code Online (Sandbox Code Playgroud)
如果我添加一些 qoute (" "/' ') 我会在里面得到这一行:
"<fmt:message key="insert_word" />"
Run Code Online (Sandbox Code Playgroud)
不是 insert_word 的翻译。
我不能做什么?
我是JSP编程的新手,正在为一个家庭成员编写一个Web应用程序.在我学习的过程中,我听到很多关于如何将JSP用于表示,而servlet用于业务逻辑.我的问题基本上是关于这种情况有多远以及何时使用JSTL是不好的做法.这是一个例子:我有一个我的应用程序的登录页面,我正在使用c:如果自定义函数连接到我的java类来处理表单.这会被认为是糟糕的MVC实践,或者,因为我只是从EL引用我的逻辑代码,这是JSP的合法使用吗?