小编mas*_*san的帖子

应该何时创建/打开EntityManagerFactory实例?

好的,我阅读了一些文章/示例如何在单例中编写实体管理器工厂.

其中一个对我来说最容易理解:

http://javanotepad.blogspot.com/2007/05/jpa-entitymanagerfactory-in-web.html

我了解到EntityManagerFactory(EMF)应该只在应用程序范围内创建一次.

并确保在使用后关闭EMF(?)

所以我编写了EMF helper类来使用的业务方法:

public class EmProvider {

    private static final String DB_PU = "KogaAlphaPU";

    public static final boolean DEBUG = true;

    private static final EmProvider singleton = new EmProvider();

    private EntityManagerFactory emf;

    private EmProvider() {}

    public static EmProvider getInstance() {
        return singleton;
    }


    public EntityManagerFactory getEntityManagerFactory() {
        if(emf == null) {
            emf = Persistence.createEntityManagerFactory(DB_PU);
        }
        if(DEBUG) {
            System.out.println("factory created on: " + new Date());
        }
        return emf;
    }

    public void closeEmf() {
        if(emf.isOpen() || emf …
Run Code Online (Sandbox Code Playgroud)

java singleton jpa entitymanager

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

IHTMLScriptElement在哪里?

我今天刚开始使用Visual Studio 2010 C#IDE.

我正在尝试向WebBrowser组件注入javascript并遵循stackoverflow的答案:

如何在WebBrowser控件中注入Javascript?

HtmlElement txtBox = webBrowser1.Document.GetElementById("UserEmailShortcut");
//js
HtmlElement scriptOne = webBrowser1.Document.CreateElement("script");
IHTMLScriptElement element = (IHTMLScriptElement)scriptOne.DomElement;
element.text = "function sayHello() { alert('hello') }";
txtBox.AppendChild(scriptOne);
webBrowser1.Document.InvokeScript("sayHello");
Run Code Online (Sandbox Code Playgroud)

现在IHTMLScriptElement下面有红色波浪线说:

 Error  1   The type or namespace name 'IHTMLScriptElement' 
could not be found (are you missing a using directive or an assembly reference?)
    C:\Users\m-tak\documents\visual studio
 2010\Projects\winformWithWebBrowserTest\winformWithWebBrowserTest\Form1.cs
    25  13  winformWithWebBrowserTest
Run Code Online (Sandbox Code Playgroud)

我看过文档 http://msdn.microsoft.com/en-us/library/aa768904(v=VS.85).aspx

但我无法理解为什么.这不是已经包括在内,只需要包括像" using IHTMLScriptElement"(这不起作用..)

.net c#

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

如何批量循环逗号分隔的字符串?

视窗

根据帖子(dos批处理通过分隔字符串),我在下面编写了一个脚本,但没有按预期工作.

目标:给定字符串"Sun,Granite,Twilight",我想在循环中获取每个主题值,以便我可以使用该值进行一些处理.

当前输出不正确:

list = "Sun,Granite,Twilight"
file name is "Sun Granite Twilight"
Run Code Online (Sandbox Code Playgroud)

对于第一次迭代,它应该是:

list = "Sun,Granite,Twilight"
file name is "Sun"
Run Code Online (Sandbox Code Playgroud)

然后第二次迭代应该是"文件名是"花岗岩"等等.我做错了什么?

码:

set themes=Sun,Granite,Twilight

call :parse "%themes%"
goto :end

:parse
setlocal
set list=%1
echo list = %list%
for /F "delims=," %%f in ("%list%") do (
    rem if the item exist
    if not "%%f" == "" call :getLineNumber %%f
    rem if next item exist
    if not "%%g" == "" call :parse "%%g"
)
endlocal

:getLineNumber
setlocal
echo …
Run Code Online (Sandbox Code Playgroud)

batch-file

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

为什么'substring(startIndex,endIndex)'不会抛出"超出范围"

在Java中我使用的substring()方法,我不知道为什么它不会抛出"out of index"错误.

该字符串的abcde索引从0开始到4,但该substring()方法将startIndex和endIndex作为参数,基于我可以调用foo.substring(0)并获取"abcde"的事实.

那么为什么子串(5)有效呢?该指数应该超出范围.解释是什么?

/*
1234
abcde
*/
String foo = "abcde";
System.out.println(foo.substring(0));
System.out.println(foo.substring(1));
System.out.println(foo.substring(2));
System.out.println(foo.substring(3));
System.out.println(foo.substring(4));
System.out.println(foo.substring(5));
Run Code Online (Sandbox Code Playgroud)

此代码输出:

abcde
bcde
cde
de
e
     //foo.substring(5) output nothing here, isn't this out of range?
Run Code Online (Sandbox Code Playgroud)

当我用6替换5时:

foo.substring(6)
Run Code Online (Sandbox Code Playgroud)

然后我得到错误:

Exception in thread "main" java.lang.StringIndexOutOfBoundsException:
    String index out of range: -1
Run Code Online (Sandbox Code Playgroud)

java substring

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

我什么时候应该使用html5 sessionStorage?

我已经学会了sessionStorage(在会话期间持续)和localStorage(如果没有删除则永远存在)之间的区别.

我可以看到它localStorage可以用作更好的cookie版本.(更大的尺寸,不是像cookie那样为每个HTTP请求前往服务器).

但是,因为sessionStorage,我在想什么时候才能有效地使用它?

我想到用户输入到pageA中的文本字段,然后在同一个选项卡或浏览器窗口中移动到pageB,pageB可以查找sessionStorage.

我不能真正扩展我的猜测,而不是上面的场景.谁能告诉我sessionStorage怎么用?

html html5 local-storage web-storage

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

为什么service.getPathInfo()在service方法中返回null?

我写了Front Controller Pattern并运行测试.不知何故,request.getPathInfo()在返回路径信息时返回null.

1.调用servlet的HTML

<a href="tmp.do">Test link to invoke cool servlet</a>
Run Code Online (Sandbox Code Playgroud)

2.在DD中映射servlet.
任何有.do扩展名(ex tmp.do)的东西都会调用servlet"Redirector"

<!-- SERVLET (centralized entry point) -->
    <servlet>
        <servlet-name>RedirectHandler</servlet-name>
        <servlet-class>com.masatosan.redirector.Redirector</servlet-class>
    </servlet>
    <servlet-mapping>
        <servlet-name>RedirectHandler</servlet-name>
        <url-pattern>*.do</url-pattern>
    </servlet-mapping>
Run Code Online (Sandbox Code Playgroud)

3.从*.do接收请求的servlet

 public class Redirector extends HttpServlet {

        protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
            try {
                //test - THIS RETURNS NULL!!!!
                System.out.println(request.getPathInfo());

                Action action = ActionFactory.getAction(request); //return action object based on request URL path
                String view = action.execute(request, response); //action returns String (filename) 
                if(view.equals(request.getPathInfo().substring(1))) {
                    request.getRequestDispatcher("/WEB-INF/" + view + …
Run Code Online (Sandbox Code Playgroud)

service jsp tomcat servlets

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

如果在Java中它是整数数组,如何检查null元素?

我是Java的新手,并且在整数数组中检查null元素时遇到问题.我正在使用Eclipse进行编辑,并且检查null元素的行显示错误:

抱怨的行:

if(a[i] != null) {
Run Code Online (Sandbox Code Playgroud)

来自Eclipse的错误信息:

The operator != is undefined for the argument type(s) int, null
Run Code Online (Sandbox Code Playgroud)

在PHP中,这没有任何问题,但在Java中,似乎我必须将数组类型从整数更改为Object以使该行不被抱怨(如下所示)

Object[] a = new Object[3];
Run Code Online (Sandbox Code Playgroud)

所以我的问题是,如果我仍然想要声明为整数数组并且仍然想要检查null,它的语法是什么?

码:

public void test() {
        int[] a = new int[3];
        for(int i=0; i<a.length; i++) {
            if(a[i] != null) { //this line complains...
                System.out.println('null!');
            }
        }
    }
Run Code Online (Sandbox Code Playgroud)

java arrays int null

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

如何从webbrowser控件获取onclick中的实际JavaScript值?

我正在寻找一种方法来获取onclick中定义的JavaScript代码.我正在使用.NET 2.0 C#Visual Studio 2005.

例:

<span id="foo" onclick+"window.location.href='someURL'>click here</span>
Run Code Online (Sandbox Code Playgroud)

我的目标是获取字符串"window.location.href ='someURL'".

场景:

用户点击Web页面元素,例如上面显示的标记,在WebBrowser控件内部.然后点击标签被吹罚至H tmlElement object.

在WebBrowser控件中我然后调用HtmlElement object's getAttribute("onclick")它,它只给我" System .__ ComObject".

我已经搜索了如何处理它然后发现它可以被铸造然后获得价值.

if (tag.GetAttribute("onclick").Equals("System.__ComObject"))
{
    Console.WriteLine("dom elem  >>>>>>>>>>> " + tag.DomElement.ToString());
    mshtml.HTMLSpanElementClass span = (mshtml.HTMLSpanElementClass)tag.DomElement;

    Console.WriteLine("js value ===>" + span.onclick);
}
Run Code Online (Sandbox Code Playgroud)

输出:

dom elem  >>>>>>>>>>> mshtml.HTMLSpanElementClass
js value ===> System.__ComObject
Run Code Online (Sandbox Code Playgroud)

如图所示,span.onclick仍然给我System .__ ComObject,我做错了什么?

为什么的HtmlElement的的getAttribute()方法返回"mshtml.HTMLInputElementClass",而不是属性的值? 这家伙说它在他的情况下工作,我跟着它,但我的有点不工作......

UPDATE

研究,研究.....

我可以在我的C#项目中添加引用VisualBasic.dll然后调用该方法来找出这个系统是谁.__ ComObject确实是.

Console.WriteLine(Microsoft.VisualBasic.Information.TypeName(span.onclick));
Run Code Online (Sandbox Code Playgroud)

输出:

JScriptTypeInfo
Run Code Online (Sandbox Code Playgroud)

看起来这是一个JScript类型......我该如何访问这个对象?

更多详情

以上描述基于我目前的项目.该项目旨在创建像Selenium IDE这样的东西.它使用WebBrowser控件.

Selenium IDE创建了3种不同的东西来记录Web文档中的元素.

1. actionType
2. xpath
3. …
Run Code Online (Sandbox Code Playgroud)

c# browser visual-studio-2005 selenium-ide comobject

13
推荐指数
2
解决办法
7549
查看次数

如何更改jQuery UI Dialog的背景颜色?

我很难弄清楚如何改变背景颜色jQuery UI Dialog.

我见过很多参考如何更改/删除标题栏但不包括整个背景,包括那些弯曲的角落.

这是我的尝试:

http://jsfiddle.net/dEvKb/11/

问题是.ui-widget-content仅适用于对话框中的方形区域,但不包括弯曲的角落.

我发现了一个类.ui-corner-all类,希望它能为整个背景着色,但只有一半的对话框是彩色的.(你可以在jsfiddle中看到这个)

有没有人这样做过?

javascript jquery styles dialog

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

REST如何传递空路径参数?

我正在REST使用构建Web应用程序Netbean 7.1.1 Glassfish 3.1.2

我有2个网址:

"http://myPage/resource/getall/name"  (get some data by name)

"http://myPage/resource/getall" (get all data)
Run Code Online (Sandbox Code Playgroud)

当客户端使用第一个URL发送请求时,将调用下面的servlet并执行一些处理.

@Path("getall/{name}")
@GET
@Produces("application/json")
public Object Getall(@PathParam("name") String customerName) {
      //here I want to call SQL if customerName is not null. is it possible???
}
Run Code Online (Sandbox Code Playgroud)

但我也想要第二个URL来调用这个servlet.

我以为servlet会被调用,我可以检查customerName == null然后调用不同的SQL等等.

但是当客户端使用第二个URL(即没有路径参数)发送请求时,不会调用servlet,因为URL没有{name} path参数.

是不是可以调用第二个URL并调用上面的servlet?

我能想到的一个替代方案是使用query parameter:

http://myPage/resource/getall?name=value
Run Code Online (Sandbox Code Playgroud)

也许我可以解析它,看看是否"value"为null然后采取相应的行动..

java rest jax-rs

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