假设我有下一个标记:
<div id="content">
<div id="firstP"><p>First paragraph</p></div>
<div id="secondP"><p>Second paragraph</p></div>
<div id="thirdP"><p>Third paragraph</p></div>
<div id="fourthP"><p>Fourth paragraph</p></div>
</div>
Run Code Online (Sandbox Code Playgroud)
我想用Javascript添加一个新的div并专注于这个新元素.焦点没有做任何事情.
function addParagraph() {
var html = "<div id=\"newP\"><p>New paragraph</p></div>";
$("#content").append(html);
$("#newP").focus();
}
Run Code Online (Sandbox Code Playgroud)
任何的想法?
我想将主JPS中的List类型对象传递给include JSP(jsp:include).由于parm只支持字符串,因此我无法使用parm标记将List类型数据传递给include文件.
使用示例:
<jsp:include page="/jsp/appList.jsp">
<jsp:param name="applications" value="${applications}"/>
</jsp:include>
Run Code Online (Sandbox Code Playgroud)
要么:
<jsp:include page="/jsp/appList.jsp">
<jsp:param name="applications" value="${confirmed_applications}"/>
</jsp:include>
<jsp:include page="/jsp/appList.jsp">
<jsp:param name="applications" value="${unconfirmed_applications}"/>
</jsp:include>
<jsp:include page="/jsp/appList.jsp">
<jsp:param name="applications" value="${canceled_applications}"/>
</jsp:include>
Run Code Online (Sandbox Code Playgroud)
我可以创建一个简单的标记处理程序,但我想知道是否有更简单的方法.
我一直在尝试使用mvp4g框架构建GWT/Google App Engine Web应用程序.
我一直收到错误的错误,无法通过延迟绑定创建我的服务实例.
我的Acebankroll.gwt.xml文件如下所示:
<?xml version="1.0" encoding="UTF-8"?>
<module rename-to='acebankroll'>
<inherits name='com.google.gwt.user.User'/>
<inherits name="com.google.gwt.i18n.I18N"/>
<inherits name='com.google.gwt.user.theme.standard.Standard'/>
<inherits name='com.mvp4g.Mvp4gModule'/>
<entry-point class='com.softamo.acebankroll.client.AceBankroll'/>
<source path='client'/>
</module>
Run Code Online (Sandbox Code Playgroud)
我的入门模块如下:
public class AceBankroll implements EntryPoint {
public void onModuleLoad() {
Mvp4gModule module = (Mvp4gModule)GWT.create( Mvp4gModule.class );
module.createAndStartModule();
RootPanel.get().add((Widget)module.getStartView());
}
}
Run Code Online (Sandbox Code Playgroud)
我发布完整的错误跟踪作为答案.
我已经读过,下一个常见错误列表可能会导致此错误:
ServiceAsync接口具有返回值的方法.这是错误的,所有方法都需要返回void.
Service接口不扩展RemoteService接口.
ServiceAsync接口中的方法错过了AsyncCallback的最后一个参数.
两个interfaced,ExampleService和ExampleServiceAsync上的方法不完全匹配(除了返回值和AsyncCallback参数)
我检查了上述所有条件,但未发现问题.
这是一个片段,说明我如何在演示者类中注入服务.
protected MainServiceAsync service = null;
@InjectService
public void setService( MainServiceAsync service ) {
this.service = service;
}
Run Code Online (Sandbox Code Playgroud)
我有三个表:页面,附件,页面附件
我有这样的数据:
page
ID NAME
1 first page
2 second page
3 third page
4 fourth page
attachment
ID NAME
1 foo.word
2 test.xsl
3 mm.ppt
page-attachment
ID PAGE-ID ATTACHMENT-ID
1 2 1
2 2 2
3 3 3
Run Code Online (Sandbox Code Playgroud)
我想在该数字为0时获得每页的附件数量.我尝试过:
select page.name, count(page-attachment.id) as attachmentsnumber
from page
inner join page-attachment on page.id=page-id
group by page.id
Run Code Online (Sandbox Code Playgroud)
我得到这个输出:
NAME ATTACHMENTSNUMBER
second page 2
third page 1
Run Code Online (Sandbox Code Playgroud)
我想得到这个输出:
NAME ATTACHMENTSNUMBER
first page 0
second page 2
third page 1 …Run Code Online (Sandbox Code Playgroud) 在欧洲,小数用' , ' 分隔,我们使用可选' .'分开成千上万.我允许货币值:
我使用下一个正则表达式(来自RegexBuddy库)来验证输入.我允许可选的两位数分数和可选的千位分隔符.
^[+-]?[0-9]{1,3}(?:[0-9]*(?:[.,][0-9]{0,2})?|(?:,[0-9]{3})*(?:\.[0-9]{0,2})?|(?:\.[0-9]{3})*(?:,[0-9]{0,2})?)$
Run Code Online (Sandbox Code Playgroud)
我想将货币字符串解析为浮点数.例如
123,456.78应存储为123456.78
123.456,78应存储为123456.78
123.45应存储为123.45
1.234应存储为1234 12.34应存储为12.34
等等...
在Java中有一种简单的方法吗?
public float currencyToFloat(String currency) {
// transform and return as float
}
Run Code Online (Sandbox Code Playgroud)
使用BigDecimal而不是Float
感谢大家的回答.我已将我的代码更改为使用BigDecimal而不是float.我会用浮动来保留这个问题的前一部分,以防止人们犯同样的错误.
解
下一个代码显示了一个函数,它将美国和欧盟货币转换为BigDecimal(String)构造函数接受的字符串.这就是说一个没有千分隔符的字符串和一个分数点.
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class TestUSAndEUCurrency {
public static void main(String[] args) throws Exception {
test("123,456.78","123456.78");
test("123.456,78","123456.78");
test("123.45","123.45");
test("1.234","1234");
test("12","12");
test("12.1","12.1");
test("1.13","1.13");
test("1.1","1.1");
test("1,2","1.2");
test("1","1");
}
public static void test(String value, String expected_output) throws Exception {
String output = currencyToBigDecimalFormat(value);
if(!output.equals(expected_output)) {
System.out.println("ERROR expected: " …Run Code Online (Sandbox Code Playgroud) 我想得到类似JSTL中生成的下一个代码
<c:choose>
<c:when test="${random number is even}">
<div class="redlogo">
</c:when>
<c:otherwise>
<div class="greenlogo">
</c:otherwise>
</c:choose>
Run Code Online (Sandbox Code Playgroud) 我有以下HTML代码:
<h3 id="headerid"><span onclick="expandCollapse('headerid')">⇑</span>Header title</h3>
Run Code Online (Sandbox Code Playgroud)
每次用户点击span标记时,我都希望在向上箭头和向下箭头之间切换.
function expandCollapse(id) {
var arrow = $("#"+id+" span").html(); // I have tried with .text() too
if(arrow == "⇓") {
$("#"+id+" span").html("⇑");
} else {
$("#"+id+" span").html("⇓");
}
}
Run Code Online (Sandbox Code Playgroud)
我的功能始终是其他路径.如果我做一个javacript:arrow变量的警告我得到的html实体表示为箭头.我如何告诉jQuery将arrow变量解释 为字符串而不是html.
我希望我的Web应用程序用户将一些数据下载为Excel文件.
我有下一个函数在响应对象中发送输入流.
public static void sendFile(InputStream is, HttpServletResponse response) throws IOException {
BufferedInputStream in = null;
try {
int count;
byte[] buffer = new byte[BUFFER_SIZE];
in = new BufferedInputStream(is);
ServletOutputStream out = response.getOutputStream();
while(-1 != (count = in.read(buffer)))
out.write(buffer, 0, count);
out.flush();
} catch (IOException ioe) {
System.err.println("IOException in Download::sendFile");
ioe.printStackTrace();
} finally {
if (in != null) {
try { in.close();
} catch (IOException ioe) { ioe.printStackTrace(); }
}
}
}
Run Code Online (Sandbox Code Playgroud)
我想将我的HSSFWorkbook对象转换为输入流并将其传递给前一个方法.
public InputStream generateApplicationsExcel() {
HSSFWorkbook wb = …Run Code Online (Sandbox Code Playgroud) 我在使用Gzip压缩和JQuery时遇到问题.它似乎可能是由我在Struts Actions中发送JSON响应的方式引起的.我使用下一个代码来发送我的JSON对象.
public ActionForward get(ActionMapping mapping,
ActionForm form,
HttpServletRequest request,
HttpServletResponse response) {
JSONObject json = // Do some logic here
RequestUtils.populateWithJSON(response, json);
return null;
}
public static void populateWithJSON(HttpServletResponse response,JSONObject json) {
if(json!=null) {
response.setContentType("text/x-json;charset=UTF-8");
response.setHeader("Cache-Control", "no-cache");
try {
response.getWriter().write(json.toString());
} catch (IOException e) {
throw new ApplicationException("IOException in populateWithJSON", e);
}
}
}
Run Code Online (Sandbox Code Playgroud)
有没有更好的方法在Java Web应用程序中发送JSON?
MySQL中的下一个功能
MD5( 'secret' )生成5ebe2294ecd0e0f08eab7690d2a6ee69
我想有一个Java函数来生成相同的输出.但
public static String md5( String source ) {
try {
MessageDigest md = MessageDigest.getInstance( "MD5" );
byte[] bytes = md.digest( source.getBytes("UTF-8") );
return getString( bytes );
} catch( Exception e ) {
e.printStackTrace();
return null;
}
}
private static String getString( byte[] bytes ) {
StringBuffer sb = new StringBuffer();
for( int i=0; i<bytes.length; i++ ) {
byte b = bytes[ i ];
sb.append( ( int )( 0x00FF & b ) );
if( …Run Code Online (Sandbox Code Playgroud) java ×5
javascript ×2
jquery ×2
jsp ×2
apache-poi ×1
count ×1
cryptographic-hash-function ×1
cryptography ×1
currency ×1
el ×1
focus ×1
gwt ×1
html ×1
json ×1
jstl ×1
md5 ×1
mvp ×1
mysql ×1
sql ×1