我可以使用twitter4j登录twitter并获取有关登录用户的信息,但我无法从我的应用程序发布推文.我正在使用java web应用程序发布推文.看到我使用的下面的代码.
String ACCESS_TOKEN = "ttttttttt";
String ACCESS_TOKEN_SECRET = "gggggggggggggg";
String CONSUMER_KEY = "gggggggggggg";
String CONSUMER_SECRET = "hhhhhhhhhhhhh";
String tweet = "";
if (request.getParameter("tweet") != null) {
tweet = request.getParameter("tweet");
}
AccessToken accessToken = new AccessToken(ACCESS_TOKEN, ACCESS_TOKEN_SECRET);
OAuthAuthorization authorization = new OAuthAuthorization(ConfigurationContext.getInstance(), CONSUMER_KEY, CONSUMER_SECRET, accessToken);
Twitter twitter = new TwitterFactory().getInstance(authorization);
try {
//twitter.updateStatus("Hello World!");
twitter.updateStatus(tweet);
} catch (TwitterException e) {
System.err.println("Error occurred while updating the status!");
}
Run Code Online (Sandbox Code Playgroud)
我得到了以下例外:
TwitterException {exceptionCode = [fa54b184-3bf2623f],statusCode = 401,retryAfter = 0,rateLimitStatus = null,version = 2.1.5-SNAPSHOT(build:d372a51b9b419cbd73d416474f4a855f3e889507)} …
我在ROR中使用bundle install时遇到此错误.
获取git://github.com/pengwynn/linkedin.git致命:无法查找github.com(端口9418)(没有这样的主机已知.)Git错误:git clone "git://github.com/pengwynn/linkedin.git" "C:/RailsInstaller/Ruby1.8.7/lib/ruby/gems/1.8/ca
che/bundler/git/linkedin-3e3919d62b37a1f8879ade6b51b3eeb032fc8973" --bare --no-hardlinks目录C中的命令:/ linkedin/linke dinfrongit失败.
我正在使用Windows.
我试图在tomcat中使用池进行数据库连接,这就是我的上下文:
<Resource name="jdbc/slingemp" auth="Container" type="javax.sql.DataSource"
maxActive="100" maxIdle="30" maxWait="10000"
username="root" password="root" driverClassName="com.mysql.jdbc.Driver"
url="jdbc:mysql://localhost:3306/slingemp"/>
Run Code Online (Sandbox Code Playgroud)
这就是我的web.xml:
<description>MySQL JNDI Test</description>
<resource-ref>
<description>DB Connection</description>
<res-ref-name>jdbc/slingemp</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
</resource-ref>
Run Code Online (Sandbox Code Playgroud)
这就是我与数据库连接的方式:
package org.slingemp.jnditest;
import java.io.IOException;
import java.sql.Connection;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.tomcat.jdbc.pool.DataSource;
/**
* Servlet implementation class JNDILookUpServlet
*/
@WebServlet("/JNDILookUpServlet")
public class JNDILookUpServlet extends HttpServlet {
private static final long serialVersionUID = 1L;
/**
* @see HttpServlet#HttpServlet()
*/
public JNDILookUpServlet() {
super();
// TODO Auto-generated constructor …Run Code Online (Sandbox Code Playgroud) 我想在context.xml文件中设置一些值,并从我的Servlet访问相同的内容,就像我们在JNDI中访问一样:
mail.smtp.host=smtp.gmail.com
mail.smtp.port=465
Run Code Online (Sandbox Code Playgroud)
我可以这样做吗?
我希望用户使用以下代码输入连字符
<var>
<var-name>mask</var-name>
<var-value>^[a-zA-Z0-9]*$</var-value>
</var>
Run Code Online (Sandbox Code Playgroud)
我正在使用 struts 验证。所以请帮我解决这个问题。
编辑
用户可以在字符串的任何位置输入连字符,因此对于-应该在开头、中间还是结尾没有限制。
我想检查两个日期是否超过一周,例如,检查两个日期是否有七天,
此时数据范围应仅在一周内(7天).
我试过这样的事,
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
public class IsDateRangeExceedsWeek
{
public static void main( String[] args )
{
try{
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
Date fromDate = sdf.parse("2015-05-01");
Date toDate = sdf.parse("2015-05-07");
System.out.println(sdf.format(fromDate));
System.out.println(sdf.format(toDate));
if(fromDate.compareTo(toDate)>0){
System.out.println("From Date should be less than To Date");
} else if(fromDate.compareTo(toDate)==0){
System.out.println("From Date is equal to To Date");
}
}catch(ParseException ex){
ex.printStackTrace();
}
}
}
Run Code Online (Sandbox Code Playgroud)
有人可以帮忙吗?
无论域名如何,如何验证给定的电子邮件地址都是正确的.
举个例子,如果我给
someone@gmail.com
要么
someone@yahoo.com
同样明智的是,如果我给出任何地址,系统必须能够说出给定的地址存在于域中
我正在尝试编写一个Spring(我使用3.0)应用程序并使用Spring包含的Javamail.我希望将javamail属性(stmp服务器,端口,用户名,传递等)存储在数据库中以便于更新/更改.我已经看到了在applicationContext.xml or in a properties文件中设置Javamail属性的示例.
但 is there a way to use a database to store the email properties and retrieve them every time I need to send a e-mail?
我的ApplicationContex.xml
<bean id="mailSender" class="org.springframework.mail.javamail.JavaMailSenderImpl">
<property name="defaultEncoding" value="UTF-8" />
<property name="host" value="smtp.gmail.com" />
<property name="port" value="465" />
<property name="protocol" value="smtps" />
<property name="username" value="test@gmail.com" />
<property name="password" value="***********" />
<property name="javaMailProperties">
<props>
<prop key="mail.smtps.auth">true</prop>
<prop key="mail.smtps.starttls.enable">true</prop>
<prop key="mail.smtps.debug">true</prop>
</props>
</property>
</bean>
Run Code Online (Sandbox Code Playgroud)
谢谢你的帮助.
我尝试了以下内容,并java.lang.UnsupportedOperationException在尝试向其添加新元素时看到它抛出.
基本上我尝试将Array转换为ArrayList,并尝试在从数组到ArrayList协调后添加新元素.
我的计划是:
public class ArrayToList {
public static void main(String[] args) {
String[] asset = {"equity", "stocks", "gold", "foreign exchange","fixed income", "futures", "options"};
List<String> assetList = Arrays.asList(asset);
for (String object : assetList) {
System.out.println("object : "+object);
}
assetList.add("test");
}
}
Run Code Online (Sandbox Code Playgroud)
例外:
Exception in thread "main" java.lang.UnsupportedOperationException
at java.util.AbstractList.add(Unknown Source)
at java.util.AbstractList.add(Unknown Source)
at anto.com.collection.ArrayToList.main(ArrayToList.java:15)
Run Code Online (Sandbox Code Playgroud)
如果我们无法在转换后的值中添加或删除元素,那么从数组转换为Arraylist有什么用?
谢谢
我试图从列表中删除对象,我得到以下异常:
failure:java.util.ConcurrentModificationException null
Run Code Online (Sandbox Code Playgroud)
这就是我尝试从列表中删除对象的方法:
private List<testVO> removeDuplicateEntries(List<testVO> sessionList,List<testVO> dbList){
for (Iterator<testVO> dbIterator = dbList.listIterator(); dbIterator.hasNext(); ) {
testVO voDB = dbIterator.next();
for (Iterator<testVO> sessionIterator = sessionList.iterator(); sessionIterator.hasNext();) {
testVO voSession = (testVO) sessionIterator.next();
if(voDB.getQuestionID().intValue() == voSession.getQuestionID().intValue()){
//remove the object from sesion list
sessionIterator.remove();
//Add the object from DB to session list
sessionList.add(voDB);
}
}
}
return sessionList;
}
Run Code Online (Sandbox Code Playgroud)
我想删除当前的副本sessionList并添加来自的重复项dbList.
我有一个类,它有静态成员,也有非静态成员,如:
public class StaticClassObjectCreations {
public static void doSomeThing() {
// TODO implementations static
}
public void nonStaticMethod() {
// TODO implementations for non static
}
public static void main(String[] args) {
StaticClassObjectCreations obj = new StaticClassObjectCreations();
StaticClassObjectCreations obj1 = new StaticClassObjectCreations();
}
}
Run Code Online (Sandbox Code Playgroud)
正如我们所看到的那样,可以number of object creation is not restricted在使用new关键字创建的对象的帮助下访问非静态方法.
静态方法或成员变量也可用于每个实例,也可以在不创建对象的情况下访问它们.
现在我的问题是:JVM如何维护静态代码块的实例,换句话说,在使用new关键字创建对象时,这些静态块会发生什么.
谢谢.
我有两个Long数组元素,都有一些值
Long[] firstArray = new Long[10];
Long[] secondArray = new Long[25];
Run Code Online (Sandbox Code Playgroud)
阵列的大小可以相同或不同.
firstArray[0] = new Long("1");
firstArray[1] = new Long("2");
firstArray[2] = new Long("3");
secondArray [0] = new Long("2");
secondArray [1] = new Long("3");
Run Code Online (Sandbox Code Playgroud)
我想比较secondArray与firstArray和创建一个新的thirdArray与不在值secondArray.
在上面的例子中,thirdArray只有1
这是我在java中获取日期的方法:
Date date = (new GregorianCalendar(year,month - 1, i)).getTime(); // year,month,day
SimpleDateFormat f = new SimpleDateFormat("EEEE");
nameofday = f.format(date);
Run Code Online (Sandbox Code Playgroud)
当我打印日期对象时,它给出了如下答案:
Sun Apr 01 00:00:00 IST 2012
Mon Apr 02 00:00:00 IST 2012
Tue Apr 03 00:00:00 IST 2012
Wed Apr 04 00:00:00 IST 2012
Thu Apr 05 00:00:00 IST 2012
Fri Apr 06 00:00:00 IST 2012
Sat Apr 07 00:00:00 IST 2012
Run Code Online (Sandbox Code Playgroud)
从这个我想只得到前一天:01,02,03,04,05等.
如何在java中执行此操作?
关心托尼