小编Mun*_*ian的帖子

如何使用javascript转义正则表达式特殊字符?

我需要使用java脚本转义正则表达式特殊字符.如何实现这一点?任何帮助都应该被理解.


感谢您的快速回复.但我需要逃避正则表达式的所有特殊字符.我已经尝试了这段代码,但我无法达到结果.

RegExp.escape=function(str)
            {
                if (!arguments.callee.sRE) {
                    var specials = [
                        '/', '.', '*', '+', '?', '|',
                        '(', ')', '[', ']', '{', '}', '\\'
                    ];
                    arguments.callee.sRE = new RegExp(
                    '(\\' + specials.join('|\\') + ')', 'gim'
                );
                }
                return str.replace(arguments.callee.sRE, '\\$1');

            }

function regExpFind() {
            <%--var regex = new RegExp("\\[munees\\]","gim");--%>
                    var regex= new RegExp(RegExp.escape("[Munees]waran"));
                    <%--var regex=RegExp.escape`enter code here`("[Munees]waran");--%>
                    alert("Reg : "+regex);
                }
Run Code Online (Sandbox Code Playgroud)

这段代码我错了什么?请指导我.

javascript regex

152
推荐指数
3
解决办法
33万
查看次数

使用<h:graphicImage>或<img>标记从webapps/webcontext/deploy文件夹外部加载图像

我需要使用JSF <h:graphicimage>标记或HTML <img>标记在Web应用程序中显示驻留在deploy文件夹之外的图像.我怎样才能做到这一点?

jsf image jsf-2 graphicimage

42
推荐指数
1
解决办法
7万
查看次数

MalformedByteSequenceException:2字节UTF-8序列的无效字节2

我有一个包含阿拉伯字符的xml文件.当我尝试解析文件时,会出现Exception,MalformedByteSequenceException:2字节UTF-8序列的无效字节2.我使用POI DOM来解析文档.

日志是,

2012-03-19 11:30:00,433 [ERROR] (com.infomindz.remitglobe.bll.remittance.BlackListBean) - Error 

com.sun.org.apache.xerces.internal.impl.io.MalformedByteSequenceException: Invalid byte 2 of 2-byte UTF-8 sequence.

    at com.sun.org.apache.xerces.internal.impl.io.UTF8Reader.invalidByte(Unknown Source)

    at com.sun.org.apache.xerces.internal.impl.io.UTF8Reader.read(Unknown Source)

    at com.sun.org.apache.xerces.internal.impl.XMLEntityScanner.load(Unknown Source)

    at com.sun.org.apache.xerces.internal.impl.XMLEntityScanner.skipChar(Unknown Source)

    at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl$FragmentContentDriver.next(Unknown Source)

    at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl.next(Unknown Source)

    at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanDocument(Unknown Source)

    at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(Unknown Source)

    at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(Unknown Source)

    at com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(Unknown Source)

    at com.sun.org.apache.xerces.internal.parsers.DOMParser.parse(Unknown Source)

    at com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderImpl.parse(Unknown Source)

    at javax.xml.parsers.DocumentBuilder.parse(Unknown Source)

    at com.infomindz.remitglobe.bll.remittance.BlackListBean.updateGeneralBlackListDetail(Unknown Source)

    at com.infomindz.remitglobe.bll.remittance.schedulers.BlackListUpdateScheduler.executeInternal(Unknown Source)

    at org.springframework.scheduling.quartz.QuartzJobBean.execute(QuartzJobBean.java:86)

    at org.quartz.core.JobRunShell.run(JobRunShell.java:216)

    at org.quartz.simpl.SimpleThreadPool$WorkerThread.run(SimpleThreadPool.java:549)
Run Code Online (Sandbox Code Playgroud)

例外情况只出现在Windows机器上,而不是出现在Linux机器上.如何解决这个问题.任何建议都应该引人注意.

java xml apache-poi

18
推荐指数
2
解决办法
7万
查看次数

FacesMessage Jsf中的新行字符

我想显示错误消息,如"以下标题无效

1.Name
2.Roll no
Run Code Online (Sandbox Code Playgroud)

如何在jsf中使用faces消息显示这个?请帮帮我.

java jsf richfaces

7
推荐指数
2
解决办法
1万
查看次数

tomcat中的空会话路径是什么?

我前一天读过apache tomcat文档,我很困惑emptySessionPath.据我所知,如果设置为true,emptySessionPath则存储在Web应用程序的根文件夹中.请给出正确的术语定义, emptySessionPath如果设置为真和假,会发生什么?

请指导我.谢谢.

java webserver tomcat connector tomcat6

6
推荐指数
2
解决办法
1万
查看次数

会话过期和无效之间的差异

过期会话和无效会话之间有什么区别?

而且,如何使会话在java中过期?

请帮我.提前致谢.

java session session-state session-timeout session-cookies

5
推荐指数
1
解决办法
1371
查看次数

itext 中的制表符

我已经编写了使用 itext 创建报告的代码。为此,我必须添加类似于

 BSJ                        Economy Report                            Date:31/12/10
Run Code Online (Sandbox Code Playgroud)

为此,我需要将制表符 (\t) 放在上述字符串之间。但我在 itext 中找不到制表符。我使用了“\t”和“\t”。这不起作用。请帮我解决这个问题。

java itext itextsharp

5
推荐指数
1
解决办法
7153
查看次数

JPA异常:没有名为MyJPAApplicationPU的EntityManager的持久性提供程序

我是JPA的新手.我正在尝试使用JPA运行一些示例代码,但是我得到以下异常:

javax.persistence.PersistenceException: No Persistence provider for EntityManager named MyJPAApplicationPU
Run Code Online (Sandbox Code Playgroud)

我把我的异常信息放在这里,

INFO: Could not find any META-INF/persistence.xml file in the classpath
javax.persistence.PersistenceException: No Persistence provider for EntityManager named MyJPAApplicationPU
        at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:55)
        at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:33)
        at com.myJpa.TestJPA.setUp(TestJPA.java:30)
        at com.myJpa.TestJPA.main(TestJPA.java:72)
Run Code Online (Sandbox Code Playgroud)

任何帮助,将不胜感激.

java orm persistence jpa

3
推荐指数
2
解决办法
3万
查看次数

java.lang.IllegalStateException:Parent不为null,但此组件不相关

我在运行JSF程序时遇到以下异常.

    org.apache.jasper.JasperException: An exception occurred processing JSP page /pages/general/internalServerErrorPage.jsp at line 44

    41:             <link rel="shortcut icon" href="<%=request.getContextPath()%>/resources/images/infomindzicon.ico" type="image/x-icon" />
    42:         </head>
    43:         <body id="sscmsMainBody">
    44:             <h:form id="internalServerErrorPageForm" binding="#{ServerErrorBean.initForm}">
    45:                 <rich:page id="richPage" theme="#{LayoutSkinBean.layoutTheme}"
    46:                            width="#{LayoutSkinBean.layoutScreenWidth}"
    47:                            sidebarWidth="0">
Caused by: javax.servlet.ServletException: javax.servlet.jsp.JspException: java.lang.IllegalStateException: Parent was not null, but this component not related
    at org.apache.jasper.runtime.PageContextImpl.doHandlePageException(PageContextImpl.java:858)
    at org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:791)
    at org.apache.jsp.pages.general.internalServerErrorPage_jsp._jspService(internalServerErrorPage_jsp.java:207)
    at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
    at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:377)
Run Code Online (Sandbox Code Playgroud)

这个例外的含义是什么?如何解决这个问题?


更新:我的代码如下,

public HtmlForm getInitForm() {
    validateSession();
    return initForm;
}
Run Code Online (Sandbox Code Playgroud)

验证会话方法是

private void validateSession() {        
    HttpSession session …
Run Code Online (Sandbox Code Playgroud)

java jsf jsp richfaces

3
推荐指数
1
解决办法
5566
查看次数

哪一个更好的方法清除arrayList?

我需要清除数组列表,哪一种方法更好?为什么?

方法1:

List list = new ArrayList();
list.add("ram");

if(list!=null)
{
  list.clear();
}
Run Code Online (Sandbox Code Playgroud)

方法2:

List list = new ArrayList();
list.add("ram");

if(list!=null && !list.isEmpty())
{
  list.clear();
}   
Run Code Online (Sandbox Code Playgroud)

在方法1中,我不检查列表是否为空,直接我已经清除了列表.

但是在方法2中,如果列表不是空的,我已经通过检查清除了列表

if(list!=null && !list.isEmpty())
Run Code Online (Sandbox Code Playgroud)

哪一种方法更好?方法1还是方法2?

java

3
推荐指数
1
解决办法
160
查看次数