小编Pau*_* T.的帖子

如何在Ubuntu中设置Java环境路径

我刚刚在Ubuntu中使用sudo apt-get install openjdk-6-jdk命令安装了JDK,安装后的Java bin目录位于何处?我该如何设置该目录的环境路径?我对Ubuntu没什么经验,有人可以提供一些建议或建议任何好的网站供参考吗?

java ubuntu environment-variables

134
推荐指数
11
解决办法
47万
查看次数

bash getopts有多个和强制选项

是否可以使用getopts一起处理多个选项?例如,myscript -iR或myscript -irv.

此外,我有一种情况,基于条件脚本将需要强制选项.例如,如果脚本的参数是一个目录,我将需要指定-R或-r选项以及任何其他选项(myscript -iR mydir或myscript -ir mydir或myscript -i -r mydir或myscript -i -R mydir),如果只有文件-i就足够了(myscript -i myfile).

我试图搜索但没有得到任何答案.

bash getopts

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

如何使用两个提交按钮,并区分用于提交表单的按钮?

目前,我有一个HTML表单,用户将在其中输入文章的标题和文本.在提交时,它们会显示两个按钮.一种是"保存"他们的文章而不发布它,另一种是"发布"文章并将其公之于众.

我正在使用PHP,我试图弄清楚如何分辨使用哪个按钮,以便在数据库中存储适当的相应值.

<td>
<input type="submit" class="noborder" id="save" value="" alt="Save" tabindex="4" />
</td>
<td>
<input type="submit" class="noborder" id="publish" value="" alt="Publish" tabindex="5" />
</td>
Run Code Online (Sandbox Code Playgroud)

可能应该早些提到过这个,但我无法分配按钮值,因为按钮是一个图像,所以文本会显示在它上面.

php forms action submit

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

如何在Java中从该方法中查找方法名称?

我想知道是否有办法知道在运行时执行的方法名称?

例如,在private void doSomething (String s)方法内部,我想知道我正在执行该doSomething (String s)方法.

java methods

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

Java:String:equalsIgnoreCase vs将所有内容切换为大写/小写

我注意到有几种方法可以比较Java中的字符串.

我很久以前习惯使用equalsIgnoreCase以避免出现区分大小写的字符串问题.

另一方面,其他人喜欢以大写或小写的方式传递所有内容.

从我的立场(即使技术上我坐着),我看不出真正的区别.

有人知道一种做法是否优于另一种做法?如果是这样,为什么?

java string string-comparison

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

如何在Java中自动记录方法的进入/退出?

现在我java.util.logging用来记录我的Java项目中每个方法的入口和出口点.这在调试时非常有用.

我在每个方法的开头都有这段代码,最后是类似的代码:

if (logger.isLoggable(Level.FINER)) {
    logger.entering(this.getClass().getName(), "methodName");
}
Run Code Online (Sandbox Code Playgroud)

其中"methodName"是方法的名称(硬编码).

所以我想知道是否有办法自动执行此操作,而无需在每个方法中包含此代码.

java methods logging java.util.logging

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

在Selenium WebDriver中设置加载页面的实际超时时间?

我正在测试一个包含大量代理的站点,问题是其中一些代理非常慢.因此我的代码时不时地加载页面.

from selenium import webdriver

browser = webdriver.Firefox()
browser.get("http://example.com/example-page.php")
element = browser.find_element_by_id("someElement")
Run Code Online (Sandbox Code Playgroud)

我已经尝试了许多类似的东西explicit waits,implicit waits并且已经搜索了很长一段时间但仍然没有找到解决方案或解决方法.似乎没有什么真正影响页面加载线browser.get("http://example.com/example-page.php"),这就是为什么它总是卡在那里.

有人为此得到了解决方案吗?

更新1:

JimEvans的回答解决了我之前的问题,在这里你可以找到这个新功能的python补丁.

新问题:

browser = webdriver.Firefox()
browser.set_page_load_timeout(30)

browser.get("http://example.com/example-page.php")

element = browser.find_element_by_id("elementA")
element.click() ## assume it's a link to a new page http://example.com/another-example.php

another_element = browser.find_element_by_id("another_element")
Run Code Online (Sandbox Code Playgroud)

正如你所看到的那样,browser.set_page_load_timeout(30)只影响browser.get("http://example.com/example-page.php")这意味着如果这个页面加载超过30秒就会抛出超时异常,但问题是它没有超过页面加载的能力,例如element.click(),尽管它不会阻塞直到新页面完全加载起来,another_element = browser.find_element_by_id("another_element")是在屁股的新的疼痛,因为无论explicit waitsimplicit waits将等待它开始寻找那些元素之前整个页面加载.在某些极端情况下,这甚至需要HOURS.我能做些什么呢?

python selenium webdriver wait selenium-webdriver

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

equal()和equalsIgnoreCase()对于相等的字符串返回false

我在mac上使用eclipse IDE(版本:3.4.2),我遇到了以下问题.

当使用equal()或equalsIgnoreCase()方法比较字符串时,即使字符串相等,我也会收到false.例如,下面的代码将以下条件视为false,即使值[0] ="debug_mode"

if (values[0].equalsIgnoreCase("debug_mode")) 
    debug_mode = true;
Run Code Online (Sandbox Code Playgroud)

这是以下循环的一部分:

String value = dis.readLine();
String values[] = value.trim().split("=");
if (values.length >= 2)
{
    Config.prnt_dbg_msg(values[0] + "\t" + values[1]);
    if (values[0].equalsIgnoreCase("debug_mode")) 
        debug_mode = isTrue(values[1]);
    if (values[0].equalsIgnoreCase("debug_query_parsing")) 
        debug_query_parsing = isTrue(values[1]);
    if (values[0].equalsIgnoreCase("username")) 
        Connection_Manager.alterAccessParameters(values[1], null, null);
    if (values[0].equalsIgnoreCase("password")) 
        Connection_Manager.alterAccessParameters(null, values[1], null);
if (values[0].equalsIgnoreCase("database")) 
        Connection_Manager.alterAccessParameters(null, null, values[1]);
    if (values[0].equalsIgnoreCase("allow_duplicate_entries")) 
        allow_duplicate_entries = isTrue(values[1]);
}                         
Run Code Online (Sandbox Code Playgroud)

我尝试使用value[0].equal("debug_mode")并得到了相同的结果.有人知道为什么吗?

java string string-comparison

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

Python全局变量

def say_boo_twice():
  global boo
  boo = 'Boo!'
  print boo, boo

boo = 'boo boo'
say_boo_twice()
Run Code Online (Sandbox Code Playgroud)

输出是

嘘!嘘!

不像我预期的那样.既然我宣布boo为全局,为什么输出不是:

嘘嘘嘘

python variables global global-variables

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

当要解析的元素是json字符串的元素时,使用gson解析json的最简单方法是什么?

我正在使用gson将json解析为java bean.对于我使用的API,大量的json结果将结果包含为json对象的第一个属性."gson方式"似乎是创建一个等效的包装器java对象,它具有一个目标输出类型的属性 - 但这会导致不必要的一次性类.这样做有最佳实践方法吗?

例如解析: {"profile":{"username":"nickstreet","first_name":"Nick","last_name":"Street"}}

我要做:

public class ParseProfile extends TestCase {
    public void testParseProfile() {
        Gson gson = new GsonBuilder().setFieldNamingPolicy(FieldNamingPolicy.LOWER_CASE_WITH_UNDERSCORES).create();
        String profileJson = "{\"profile\":{\"username\":\"nickstreet\",\"first_name\":\"Nick\",\"last_name\":\"Street\"}}";
        ProfileContainer profileContainer = gson.fromJson(profileJson, ProfileContainer.class);
        Profile profile = profileContainer.getProfile();
        assertEquals("nickstreet", profile.username);
        assertEquals("Nick", profile.firstName);
        assertEquals("Street", profile.lastName);
    }
}

public class ProfileContainer {
    protected Profile profile;

    public Profile getProfile() {
        return profile;
    }

    public void setProfile(Profile profile) {
        this.profile = profile;
    }
}

public class Profile {
    protected String username;
    protected String firstName;
    protected String lastName; …
Run Code Online (Sandbox Code Playgroud)

java serialization parsing json gson

12
推荐指数
1
解决办法
5063
查看次数