为什么我得到IP地址为127.0.0.1
这是我用于获取IP地址的示例程序
package com;
import java.net.InetAddress;
import org.apache.log4j.Logger;
public class Test {
private static final Logger logger = Logger.getLogger(Test.class);
public static void main(String args[]) throws Exception {
String ips = InetAddress.getLocalHost().getHostAddress().trim();
System.out.println(ips);
}
}
Run Code Online (Sandbox Code Playgroud) 我有一个包含下划线的字符串,如下所示:
123445_Lisick
我想删除下划线后String中的所有字符.我已经尝试了下面的代码,它正在工作,但还有其他方法可以做到这一点,因为我需要将这个逻辑放在一个for循环中以从ArrayList中提取元素.
public class Test {
public static void main(String args[]) throws Exception {
String str = "123445_Lisick";
int a = str.indexOf("_");
String modfiedstr = str.substring(0, a);
System.out.println(modfiedstr);
}
}
Run Code Online (Sandbox Code Playgroud) 我制作了一个mongodb replicaSet,其中包含一个主要,次要和仲裁器.
我面临的问题是,当我最初启动mongodb服务器时,它正在以辅助模式启动
当我在终端上键入mongo时显示为
ubsc:SECONDARY>
Run Code Online (Sandbox Code Playgroud)
我用了创建了一个副本集
config = {with all my server details }
rs.reconfig(config)
Run Code Online (Sandbox Code Playgroud)
我也尝试过使用rs.add(serverhoststr)选项.
这低于我的mongo shell输出和日志文件
ubsc:PRIMARY> rs.status()
{
"set" : "ubsc",
"date" : ISODate("2013-10-31T19:09:26Z"),
"myState" : 1,
"members" : [
{
"_id" : 0,
"name" : "mongoA:27017",
"health" : 1,
"state" : 1,
"stateStr" : "PRIMARY",
"uptime" : 2210,
"optime" : Timestamp(1383246016, 1),
"optimeDate" : ISODate("2013-10-31T19:00:16Z"),
"self" : true
},
{
"_id" : 1,
"name" : "mongoB:27018",
"health" : 1,
"state" : 2,
"stateStr" : "SECONDARY",
"uptime" …Run Code Online (Sandbox Code Playgroud) 我在执行Casting时遇到运行时异常,如下所示
线程"main"中的异常java.lang.ClassCastException:A不能在Testing.main(Testing.java:5)强制转换为B.
public class A {
public void printA()
{
System.out.println("A");
}
}
public class B extends A{
public void printB()
{
System.out.println("B");
}
}
public class Testing {
public static void main(String args[]) {
B b = (B) new A();
b.printA();
}
}
Run Code Online (Sandbox Code Playgroud)
但为什么这个代码运行良好
因为我们在这里做同样的事情
HttpServletRequest request = (HttpServletRequest) req;
public class LogFilter implements Filter {
public void doFilter(ServletRequest req, ServletResponse res,FilterChain chain) throws IOException, ServletException {
HttpServletRequest request = (HttpServletRequest) req;
String ipAddress = request.getRemoteAddr();
chain.doFilter(req, res);
}
Run Code Online (Sandbox Code Playgroud) 在第一次迭代之后,由于变量i未定义,因此setTimeout失败,因此我在控制台中看到pollundefined错误
请原谅,我是一个java人,对UI Side知之甚少
var symbols = [ "ONE","TWO"];
var i = 0;
$(document).ready(function () {
callPoll();
});
function callPoll() {
poll(symbols[i]);
i++;
if (i < symbols.length)
setTimeout(callPoll, 1500);
}
setTimeout(callPoll, 3000);
function poll(value) {
alert('poll'+value);
}
Run Code Online (Sandbox Code Playgroud) <!DOCTYPE html>
<html>
<head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script>
$(document).ready(function(){
$("button").click(function(){
var value = $("p").removeClass("intro");
});
});
</script>
<style>
.intro
{
font-size:120%;
color:red;
}
</style>
</head>
<body>
<h1>This is a heading</h1>
<p class="intro">This is a paragraph.</p>
<p class="intro">This is another paragraph.</p>
<button>Remove the "intro" class from all p elements</button>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
嗨,
这是我删除某些课程的程序
我的问题是,我怎么知道removeclass操作是成功还是失败?
$("p").removeClass("intro"); 可以为此设置任何返回类型?
我在我的HTML中有这个
<div class="t1t2Wrapper" style="padding:0px 10px 0px">
<ul class="breadcrumb pull-left" id="mybreadcumb" brand_name_attr="General" document_id="204" style="background:none; margin-bottom:0px;">
<li>Name<i class="icon-angle-right"></i></li>
<li>Text1 Text2<i></i></li>
</ul>
</div>
Run Code Online (Sandbox Code Playgroud)
(Text1和Text2之间有两个空格)
我正在动态创建这个t1t2wrapper
$('.t1t2Wrapper').append(htmlforTree);
requested_data = [];
$('#mybreadcumb').children('li').each(function () {
requested_data.push($(this).text().trim());
})
Run Code Online (Sandbox Code Playgroud)
但显示它只显示一个空格?
这是我的傻瓜
我有一个div
<div class="Itm_discrp" style="display:block;">
<h3>Applle Drink</h3>
Hai i am very tasty
</div>
Run Code Online (Sandbox Code Playgroud)
我需要把文字取为"海我很好吃"
我尝试如下所示
var item_description = $(this).closest('.lastItm_Wrap').find('.Itm_discrp h3').text().trim();
Run Code Online (Sandbox Code Playgroud)
但我得到了 Applle Drink
在这种情况下,你能告诉我如何取出"Hai i is very tasty"而不是"Applle drink"的文字
当我运行以下程序时
package com.util;
import java.util.ArrayList;
public class Test {
public static void main(String[] args) throws Exception {
ArrayList<String> list_of_symbols = new ArrayList<String>();
list_of_symbols.add("ABB");
list_of_symbols.add("ACC");
list_of_symbols.add("SBIN");
StringBuilder sb_builder = new StringBuilder();
for (int i = 0; i < list_of_symbols.size(); i++) {
sb_builder.append(list_of_symbols.get(i) + ",");
}
String sql = "Select * from data where symbol_name IN ("
+ sb_builder.deleteCharAt(sb_builder.length() - 1).toString()
+ ")";
System.out.println(sql);
}
}
Run Code Online (Sandbox Code Playgroud)
SQL IS的结果
Select * from data where symbol_name IN (ABB,ACC,SBIN)
Run Code Online (Sandbox Code Playgroud)
应该在哪里作为预期结果
Select * from data where …Run Code Online (Sandbox Code Playgroud) 我有两个字段,即手机号码和密码
当焦点在手机号码文本字段上并且当用户按下Tab键时焦点不会移动到密码字段 ??
这是我的 HTML 页面
<div class="createAccountWrap">
<div class="row-fluid">
<label class="fieldLabel">Mobile Number</label>
<div class="insideInput"><input type="tel" placeholder="Mobile Number" maxlength="10" autocomplete="off" id="vmobilenum" name="vmobilenum" onkeypress="return isNumberKey(event)" required><a href="#" class=""></a></div>
</div>
<div class="row-fluid">
<label class="fieldLabel">Password</label>
<div class="insideInput"><input type="password" placeholder="Password" autocomplete="off" id="vpwdcode" name="vpwdcode" onkeypress="return nospecialCharacters(event)" required><a href="#" class=""></a></div>
</div>
</div>
Run Code Online (Sandbox Code Playgroud)
你能告诉我为什么它不起作用吗?