这是我的正则表达式模式: [Ss]ection\s\d+(?![a-zA-z])(?!</ref>)
例如,它应匹配:section 5或section 50
例如,它应该不匹配:section 5A或section 5</ref>或section 5A</ref>或section 50A
问题是,实际上它与错误相符:http://regexr.com?33ien
虽然不确定这个模式有什么问题...
如果我有以下字符串:
String string = "My \n name \n is \n John \n Doe";
Run Code Online (Sandbox Code Playgroud)
我想分开每个单词并将其添加到arraylist:
ArrayList<String> sentence = new ArrayList<String>();
Run Code Online (Sandbox Code Playgroud)
我该怎么办?
请记住,换行可能不是\n - 它可能是任何东西.
谢谢
我正在学习EJB,并且已经使用GlassFish 4编写了一个示例程序,但是由于某种原因它无法正常工作。
index.jsp:
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@ page import="javax.ejb.EJB" %>
<%@ page import="ejbtest.utility.Utility" %>
<%@ page import="ejbtest.action.*" %>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>EJB Test</title>
</head>
<body>
<%
try {
Utility utility = new Utility();
out.println("count: " + utility.getCount() + "<br/><br/>");
Trigger1 trigger1 = new Trigger1();
out.println("trigger1 count: " + trigger1.getTriggerCount());
} catch (NullPointerException npe) {
out.println("Nullpointer caught");
}
%>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
Utility.java:
package ejbtest.utility;
import javax.ejb.Singleton;
import javax.ejb.Startup;
@Startup
@Singleton
public class Utility { …Run Code Online (Sandbox Code Playgroud) 我需要创建一个线程来侦听新的,修改过的或删除的文件的文件路径.我正在使用一个使用Spring 3,Struts 2和Hibernate 3的Web应用程序.如果我运行该项目,它将加载包含文本"Hello World"的index.jsp.
问题是当我创建一个Thread()监听文件路径并将其分配给index.jsp 的java时:
<action name="" method="runThread" class="TestThreadBean">
<result>index.jsp</result>
</action>
Run Code Online (Sandbox Code Playgroud)
然后"Hello World"文本不会出现,因为Thread永远不会停止(这是正确的,它不应该停止).我需要此Thread在后台运行,而不会干扰Web应用程序的其余部分.我不想仅为此线程创建单独的Web应用程序.此外,我不希望new每次创建new会话实例时都创建一个Thread实例,无论有多少个Session实例处于活动状态,都应该只有一个Thread实例.
我已经设置了模式Part\s[V|IV|III|II|I][:]?,问题是,Part III例如,当它遇到 时,它会确认Part I匹配并删除其他两个II。有没有办法让III模式中的 具有更高的优先级,以便将其包含在找到的内容中?
我想匹配,"foo 6"但不是"foo 6</end>".目前我的表达方式是:foo\s\d+(?!.*</end>).问题是,foo 6如果</end>字符串中有标记方式,它也将丢弃.即
foo 6匹配 - 这是正确的
foo 6</end>不匹配 - 这是正确的
foo 6 word word word word number word number word</end>不匹配 - 这是不正确的,因为foo 6这里仍然匹配.
正则表达式应该允许上述3种情况正确
如何使用此标签调用类中的特定方法?
<jsp:useBean id="user" scope="??" class="com.example.User" type="com.example.User" />
import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
public class ExecutorServiceTest {
public static void main(String args[]) {
new ExecutorServiceTest();
}
public ExecutorServiceTest() {
while (true) {
action();
}
}
public String action() {
String string = "";
ExecutorService executor = Executors.newSingleThreadExecutor();
Future<String> future = executor.submit(new Callable() {
@Override
public String call() {
return randomString();
}
});
try {
string = future.get(1, TimeUnit.MILLISECONDS);
} catch (InterruptedException | ExecutionException | TimeoutException ex) {
}
future.cancel(true); …Run Code Online (Sandbox Code Playgroud) 出于某种原因,我的下面的代码给出了例外: javax.xml.transform.TransformerConfigurationException: Could not compile stylesheet
public String removePrettyPrint(String xml) throws TransformerException, TransformerFactoryConfigurationError {
String result = "";
TransformerFactory factory = TransformerFactory.newInstance();
String source = "<?xml version=\"1.0\"?><xsl:stylesheet version=\"1.0\" xmlns:xsl=\"http://www.w3.org/1999/XSL/Transform\"> <xsl:output indent=\"no\" /> <xsl:template match=\"@*|node()\"> <xsl:copy> <xsl:apply-templates select=\"@*|node()\"/> </xsl:copy> </xsl:template></xsl:stylesheet>";
Source xslt = new StreamSource(source);
Transformer transformer = factory.newTransformer(xslt);
Source text = new StreamSource(xml);
transformer.transform(text, new StreamResult(result));
return result;
}
Run Code Online (Sandbox Code Playgroud)
这有什么问题?
我试图在页面顶部获得一个固定的标题,但由于某种原因,它继续在容器的顶部.当我使用margin-bottom或margin-top然后它仍然坚持容器.
index.css
html, body, div, span, applet, object, iframe, h1, h2, h3, h4, h5, h6, p, blockquote, pre, a, abbr, acronym, address, big, cite, code, del, dfn, em, img, ins, kbd, q, s, samp, small, strike, strong, sub, sup, tt, var, b, u, i, center, dl, dt, dd, ol, ul, li, fieldset, form, label, legend, table, caption, tbody, tfoot, thead, tr, th, td, article, aside, canvas, details, embed, figure, figcaption, footer, header, hgroup, menu, nav, output, …Run Code Online (Sandbox Code Playgroud)