How exactly does the possessive quantifier work?

At the end of the page there is at attempted explanation of how do greedy, reluctant and possessive quantifiers work: http://docs.oracle.com/javase/tutorial/essential/regex/quant.html However I tried myself an example and I don't seem to understand it fully. I will paste my results directly: Enter your regex: .*+foo Enter input string to search: xfooxxxxxxfoo No match found. Enter your

所有格量词如何工作?

在页面末尾,试图解释贪婪,不情愿和占有量词如何工作:http://docs.oracle.com/javase/tutorial/essential/regex/quant.html 然而,我尝试过自己的一个例子,我似乎并没有完全理解它。 我将直接粘贴我的结果: Enter your regex: .*+foo Enter input string to search: xfooxxxxxxfoo No match found. Enter your regex: (.*)+foo Enter input string to search: xfooxxxxxxfoo I found the text "xfooxxxxxxfoo" starting

How to precisely identify & work greedy or reluctant quantifiers?

This question already has an answer here: SCJP6 regex issue 1 answer These are the matches of d* against "ab34ef" : index 0: zero-width; index 1: zero-width; index 2: "34"; index 4: zero-width; index 5: zero-width; index 6: zero-width. This should explain your output. If the quantifier was reluctant, this would be the difference: index 2: zero-width; ind

如何准确识别和工作贪婪或不情愿的量词?

这个问题在这里已经有了答案: SCJP6正则表达式问题1答案 这些是d*与"ab34ef"的匹配: 索引0:零宽度; 索引1:零宽度; 指数2:“34”; 索引4:零宽度; 索引5:零宽度; 索引6:零宽度。 这应该解释你的输出。 如果量词不情愿,这将是不同的: 索引2:零宽度; 索引3:零宽度; 不情愿的量词尽可能少地使整个表达式匹配。

Regex greedy parse direction

I found there're two different opinions about how greedy regex is executed: one is, read all the input string and match the pattern from the back, first match entire input,the first attempt is entire string. Some articles support this opinion are Oracle offical Java tutorial: Greedy quantifiers are considered "greedy" because they force the matcher to read in, or eat, the entir

正则表达式贪婪的解析方向

我发现关于如何执行贪婪正则表达式有两种不同的观点: 一个是,读取所有输入字符串并从后面匹配模式,首先匹配整个输入,第一次尝试是整个字符串。 一些文章支持这个观点是Oracle官方的Java教程: 贪婪的量词被认为是“贪婪的”,因为它们强制匹配器在尝试第一次匹配之前读入或吃掉整个输入字符串。 如果第一次匹配尝试(整个输入字符串)失败,则匹配器将输入字符串退回一个字符,然后再次尝试,重复该过程直到找到匹配或者

Where is Java Installed on Mac OS X?

I just downloaded Java 7u17 on Mac OS 10.7.5 from here and then successfully installed it. In order to do some JNI programming, I need to know where Java installed on my Mac. I thought that inside the /Library/Java/JavaVirtualMachines/ folder, there would be a folder called 1.7.0.jdk or something, but then I found that the folder is empty. This was confirmed by running ls /Library/Java/JavaVi

Java在Mac OS X上安装在哪里?

我刚从这里下载了Mac OS 10.7.5上的Java 7u17,然后成功安装了它。 为了做一些JNI编程,我需要知道在我的Mac上安装了哪些Java。 我以为在/Library/Java/JavaVirtualMachines/文件夹里面会有一个名为1.7.0.jdk的文件夹,但后来我发现这个文件夹是空的。 这可以通过在终端中运行ls /Library/Java/JavaVirtualMachines/来确认。 我试图寻找它是否安装在别的地方,但似乎没有任何改变。 有人可以告诉我在我的Mac上安装了Java

How to avoid using scriptlets in my JSP page?

I've been told that the use of scriptlets (<%= ... %>) in my JSP pages isn't such a great idea. Can someone with a bit more java/jsp experience please give me some pointers as to how to change this code so its more 'best practice', whatever that may be? This JSP is actually my sitemesh main decorator page. Basically my web design has a tab strip and a submenu, and i wis

如何避免在JSP页面中使用scriptlet?

我被告知在我的JSP页面中使用scriptlets(<%= ...%>)并不是一个好主意。 如果有人有更多的java / jsp经验,请给我一些关于如何更改此代码的指示,以便更好地实现它,无论这可能是什么? 这个JSP实际上是我的sitemesh主装饰页面。 基本上我的网页设计有一个标签条和一个子菜单,我希望以某种方式突出显示当前标签并通过查看当前请求URI来显示正确的子菜单。 <%@ taglib uri="http://www.opensymphony.com/siteme

Show JDBC ResultSet in HTML in JSP page using MVC and DAO pattern

I'm implementing MVC using JSP and JDBC. I have imported a database class file to my JSP file and I would like to show the data of a DB table. I don't know how I should return the ResultSet from the Java class to the JSP page and embed it in HTML. How can I achieve this? In a well designed MVC approach, the JSP file should not contain any line of Java code and the servlet class shou

使用MVC和DAO模式在JSP页面中的HTML中显示JDBC ResultSet

我正在使用JSP和JDBC实现MVC。 我已经将数据库类文件导入到我的JSP文件,并且想要显示数据库表的数据。 我不知道应该如何将ResultSet从Java类返回到JSP页面并将其嵌入到HTML中。 我怎样才能做到这一点? 在设计良好的MVC方法中,JSP文件不应包含任何Java代码行,并且该servlet类不应包含任何JDBC代码行。 假设您想要在网上商店中显示产品列表,需要创建以下代码。 代表Product真实世界实体的Product类,它应该只是一个

What is the difference between JSF, Servlet and JSP?

How are JSP and Servlet related to each other? Is JSP some kind of Servlet? How are JSP and JSF related to each other? Is JSF some kind of prebuild UI based JSP like ASP.NET-MVC? JSP (JavaServer Pages) JSP is a Java view technology running on the server machine which allows you to write template text in client side languages (like HTML, CSS, JavaScript, ect.). JSP supports taglibs, which

JSF,Servlet和JSP有什么区别?

JSP和Servlet如何相互关联? JSP是某种Servlet吗? JSP和JSF如何相互关联? JSF是一种基于类似ASP.NET的MVC的预建UI吗? JSP(JavaServer Pages) JSP是在服务器机器上运行的Java视图技术 ,它允许您使用客户端语言(如HTML,CSS,JavaScript等)编写模板文本。 JSP支持taglib,后者由Java代码支持,可让您控制页面流或动态输出。 一个着名的taglib是JSTL。 JSP还支持表达式语言,可用于访问后端数据(通过页面,请求

Design Patterns web based applications

I am designing a simple web-based application. I am new to this web-based domain.I needed your advice regarding the design patterns like how responsibility should be distributed among Servlets, criteria to make new Servlet, etc. Actually, I have few entities on my home page and corresponding to each one of them we have few options like add, edit and delete. Earlier I was using one Servlet per

Design Patterns基于Web的应用程序

我正在设计一个简单的基于Web的应用程序。 我是这个基于Web的领域的新手。我需要关于设计模式的建议,比如Servlet如何分配责任,制定新的Servlet的标准等。 实际上,我的主页上只有很少的实体,并且与其中的每个实体相对应,我们只有几个选项,例如添加,编辑和删除。 早些时候,我使用了一个Servlet作为选项,如Servlet1用于添加entity1,Servlet2用于编辑entity1等,这样我们就得到了大量的servlet。 现在我们正在改变我

Reflectively checking whether a object is a valid generic argument to a method

How do you check using reflection whether a given object would be a valid parameter of a method (where the parameter and the object are generic types)? To get a bit of background, this is what I'm trying to achieve: While playing with reflective method calls I thought that it would be nice to call all methods that have a parameter of a specific type. This works well for raw types as you

反射检查对象是否是方法的有效通用参数

如何使用反射来检查给定对象是否是方法的有效参数(参数和对象是泛型类型)? 为了获得一些背景知识,我正在努力实现这一目标: 在使用反射方法调用时,我认为可以调用具有特定类型参数的所有方法。 这对于原始类型非常适用,因为您可以在其类对象上调用isAssignableFrom(Class<?> c) 。 然而,当你开始在混合中投入泛型时,它突然间并不那么容易,因为泛型不是反射的原始设计的一部分,也因为类型删除。 问题较大

How do I check if a file exists in Java?

How can I check whether a file exists, before opening it for reading in Java? (equivalent of Perl's -e $filename ). The only similar question on SO deals with writing the file and was thus answered using FileWriter which is obviously not applicable here. If possible I'd prefer a real API call returning true/false as opposed to some "Call API to open a file and catch when it thro

如何检查Java中是否存在文件?

如何在打开Java文件之前检查文件是否存在? (相当于Perl的-e $filename )。 关于SO的唯一类似问题涉及写入文件,因此使用FileWriter来回答,这在这里显然不适用。 如果可能的话,我宁愿一个真正的API调用返回true / false,而不是一些“调用API打开一个文件,并捕获它引发一个异常,你检查文本中没有文件”,但我可以忍受后者。 使用java.io.File : File f = new File(filePathString); if(f.exists() && !f.isDir