我已经尝试了2个小时,但我已经放弃了.我这样检查String的值:
if(value.equals("")||value.length()<0||value==null)
{
value = "Anynomous"
}
Run Code Online (Sandbox Code Playgroud)
但是字符串仍在打印值null.
请在此处查看此程序代码
<HTML>
<BODY>
<%!
String value ;
%>
<%
value = (String)request.getAttribute("retunval");
System.out.println("Inside New fgdf JSP");
if(value.equals("")||value.length()<0||value==null)
value = "Anonymuos";
%>
Hello <%=value%>
<BR>
</BR>
<BR>
</BR>
<a href="Test.jsp">Try Again</a>
</BODY>
</HTML>
Run Code Online (Sandbox Code Playgroud) 我需要将现有的Web应用程序导入Eclipse.
请参阅我的Web应用程序的结构,如下图所示.
http://imageshack.us/f/220/structurek.jpg/
从Eclipse IDE,使用导入我需要选择哪个选项应该使用
我从CVS导入了一个非常大的java项目.问题在于,因为它是一个非常大的项目,所以Eclipse操作就像清理,运行,复制--etc一样非常慢.能告诉我,我们怎么解决这个问题?
我正在浏览Struts1和Strust2之间的差异,我发现,Struts 1中的一个常见问题是编程抽象类而不是接口.
任何人都可以让我知道,为什么编程抽象类而不是接口是一个问题?
我对Struts2中的拦截器有疑问
Struts2提供了非常强大的使用拦截器控制请求的机制.拦截器负责大多数请求处理.它们在调用动作之前和之后由控制器调用,因此它们位于控制器和动作之间.拦截器执行记录,验证,文件上传,双提防等任务.
我从以上几行开始:
http://viralpatel.net/blogs/2009/12/struts2-interceptors-tutorial-with-example.html
在此示例中,您将看到在执行操作之前和之后如何调用拦截器以及如何将结果呈现给用户.
我已经采取了以上这些线
http://www.vaannila.com/struts-2/struts-2-example/struts-2-interceptors-example-1.html
我编写了一个基本的拦截器并将其插入我的Action类:
public class InterceptorAction implements Interceptor {
public String intercept(ActionInvocation invocation) throws Exception {
System.out.println("Action class has been called : ");
return success;
}
}
Run Code Online (Sandbox Code Playgroud)
在struts.xml
<action name="login" class="com.DBAction">
<interceptor-ref name="mine"></interceptor-ref>
<result name="success">Welcome.jsp</result>
<result name="error">Login.jsp</result>
</action>
Run Code Online (Sandbox Code Playgroud)
根据他们网站上面的语句,我假设已经在控制台上调用了这一行Action类两次(那是在Action之前和Action类之后),但是它只打印了一次?
请告诉我,如果我的理解是错误的,或者作者在那个网站上错了?
我对以下程序有疑问
请参阅下面的程序
public class Kiran {
public static void main(String args[]) {
String str = "Test";
str.replace('T', 'B');
System.out.println("The modified string is now " + str);
}
}
Run Code Online (Sandbox Code Playgroud)
我所期待的是,一旦我运行这个程序,我应该看到putput为Best,但令我惊讶的是输出是Test.
有人可以告诉我,为什么会这样?
提前致谢 .
为什么今天的日期显示为日期之前?
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
public class Test {
public static void main(String args[]) throws ParseException {
Date date = new Date();
DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
List currentObject = new ArrayList();
currentObject.add("2012-09-27");
Date ExpDate = dateFormat.parse((String) currentObject.get(0));
if (ExpDate.before(date)) {
System.out.println("true");
}
else {
System.out.println("false");
}
}
}
Run Code Online (Sandbox Code Playgroud)
有任何想法吗?
我在下面有这段代码,如图所示.我们的应用程序在由Load Balancer控制的5个Web服务器上运行,所有这些服务器都连接到一个Memcache实例.
我猜这个同步化只适用于一个实例.
请告诉我如何在5个Web服务器尝试访问Memcache时同步这段代码
public class Memcache {
private MemcachedClient memclient = null;
private static Memcache instance = null;
public static Memcache getInstance() {
if (instance == null) {
try {
synchronized (Memcache.class) {
instance = new Memcache();
}
} catch (IOException e) {
throw new RuntimeException(e);
}
}
return instance;
}
private Memcache() throws IOException {
MemcachedClientBuilder builder = new XMemcachedClientBuilder();
memclient = builder.build();
}
}
Run Code Online (Sandbox Code Playgroud) 我在Mongo DB中有一个名为updated_at的字段
这将以DB的方式查看
updated_at:NumberLong("1355754242785")
此Updated_at字段以这种方式在数据库中创建
long now = System.currentTimeMillis();
从DB Record中的一个,我已经取了一个值
updated_at" : NumberLong("1355754242785"), "volatility12" : "na", "vwap" : "0", "wk52hi" : "0", "wk52hidate" : "----"}
Run Code Online (Sandbox Code Playgroud)
例如,说它的值是1355754242785
有可能转换1355754242785,当它被更新?
当我尝试转换
public class Aim {
public static void main(String[] args) {
DateFormat formatter = new SimpleDateFormat("dd/MM/yyyy hh:mm:ss.SSS");
long now = 1355754242785; // Error here saying out of range
Calendar calendar = Calendar.getInstance();
calendar.setTimeInMillis(now);
System.out.println(now + " = " + formatter.format(calendar.getTime()));
}
}
Run Code Online (Sandbox Code Playgroud) 我有一个如图所示的课程
package com;
public class Person {
boolean registered;
public boolean isRegistered() {
return registered;
}
public void setRegistered(boolean registered) {
this.registered = registered;
}
}
Run Code Online (Sandbox Code Playgroud)
将根据DB中存在的数据设置数据到人员对象.问题是对于较旧的记录,注册的文件不存在.
所以我怎么能测试该文件是否存在?
包com;
public class Test {
public static void main(String args[]) {
Person per = new Person();
if (per.isRegistered()) {
}
}
}
Run Code Online (Sandbox Code Playgroud)
如何检查该Person对象是否存在per.isRegistered()字段?