我试图在我的POM.xml文件中添加MS SQL驱动程序依赖项,以下是依赖项.
<dependency>
<groupId>com.microsoft.sqlserver</groupId>
<artifactId>sqljdbc4</artifactId>
<version>4.0</version>
</dependency>
Run Code Online (Sandbox Code Playgroud)
但我得到了这个例外
缺少工件com.microsoft.sqlserver:sqljdbc4:jar:4.0
我真的不明白这个问题.
我有一个类似下面的值Mon Jun 18 00:00:00 IST 2012,我想将其转换为18/06/2012
怎么转换这个?
我尝试过这种方法
public String toDate(Date date) {
SimpleDateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy");
Date theDate = null;
//String in = date + "/" + month + "/" + year;
try {
theDate = dateFormat.parse(date.toString());
System.out.println("Date parsed = " + dateFormat.format(theDate));
} catch (ParseException e) {
e.printStackTrace();
}
return dateFormat.format(theDate);
}
Run Code Online (Sandbox Code Playgroud)
但它抛出以下异常:
java.text.ParseException: Unparseable date: "Mon Jun 18 00:00:00 IST 2012"
我使用下面的代码将文件上传到tomcat5.5,它给了我以下异常
java.lang.NoClassDefFoundError: org/apache/commons/io/output/DeferredFileOutputStream
你能帮我找一下吗?
import java.io.File;
import java.io.IOException;
import java.util.Iterator;
import java.util.List;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.commons.fileupload.FileItem;
import org.apache.commons.fileupload.FileItemFactory;
import org.apache.commons.fileupload.FileUploadException;
import org.apache.commons.fileupload.disk.DiskFileItemFactory;
import org.apache.commons.fileupload.servlet.ServletFileUpload;
/**
* Servlet implementation class FileUploadServlet
*/
public class FileUploadServlet extends HttpServlet {
private static final long serialVersionUID = 1L;
/**
* @see HttpServlet#HttpServlet()
*/
public FileUploadServlet() {
super();
// TODO Auto-generated constructor stub
}
/**
* @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
*/
@SuppressWarnings("rawtypes")
protected void doGet(HttpServletRequest request, HttpServletResponse response) …Run Code Online (Sandbox Code Playgroud) 我正进入(状态
"src-resolve:无法将名称'j2ee:descriptionType'解析为(n)'类型定义'组件."
我的xsd文件中的这个错误.
请帮我解决这个问题.
可能重复:
计算两个Java日期实例之间的差异
如何获取Java中两个日期之间的天数?
什么是最好的方式?这是我得到的,但它不是最好的:
public static ConcurrentHashMap<String, String> getWorkingDaysMap(int year,
int month, int day){
int totalworkingdays=0,noofdays=0;
String nameofday = "";
ConcurrentHashMap<String,String> workingDaysMap =
new ConcurrentHashMap<String,String>();
Map<String,String> holyDayMap = new LinkedHashMap<String,String>();
noofdays = findNoOfDays(year,month,day);
for (int i = 1; i <= noofdays; i++) {
Date date = (new GregorianCalendar(year,month - 1, i)).getTime();
// year,month,day
SimpleDateFormat f = new SimpleDateFormat("EEEE");
nameofday = f.format(date);
String daystr="";
String monthstr="";
if(i<10)daystr="0";
if(month<10)monthstr="0";
String formatedDate = daystr+i+"/"+monthstr+month+"/"+year;
if(!(nameofday.equals("Saturday") || nameofday.equals("Sunday"))){
workingDaysMap.put(formatedDate,formatedDate);
totalworkingdays++;
}
}
return workingDaysMap; …Run Code Online (Sandbox Code Playgroud) 我已经做了以下示例来检查我的知识
import java.util.Map;
public class HashMap {
public static Map<String, String> useDifferentMap(Map<String, String> valueMap) {
valueMap.put("lastName", "yyyy");
return valueMap;
}
public static void main(String[] args) {
Map<String, String> inputMap = new java.util.HashMap<String, String>();
inputMap.put("firstName", "xxxx");
inputMap.put("initial", "S");
System.out.println("inputMap : 1 " + inputMap);
System.out.println("changeMe : " + useDifferentMap(inputMap));
System.out.println("inputMap : 2 " + inputMap);
}
}
Run Code Online (Sandbox Code Playgroud)
输出是:
original Map : 1 {initial=S, firstName=xxxx}
useDifferentMap : {lastName=yyyy, initial=S, firstName=xxxx}
original Map : 2 {lastName=yyyy, initial=S, firstName=xxxx}
Run Code Online (Sandbox Code Playgroud)
此方法useDifferentMap获取地图并更改值并返回相同的值.修改后的地图将包含修改后的值,其范围为useDifferentMap方法的本地范围. …
我有一个如下界面:
public interface a {
public void m1();
public void m2();
public void m3();
}
public class A implements a {
public void m3() {
// implementation code
}
}
Run Code Online (Sandbox Code Playgroud)
我想避免实现其余的方法.一种方法是在尝试实现的类中没有实现所有方法interface.
我该如何避免这种情况.示例代码可以帮助我更好地理解:)
我在以下几行中得到错误.
error: incompatible types
required : java.util.Map.entry<java.lang.String,java.lang.String[]>
found :java.lang.Object
Run Code Online (Sandbox Code Playgroud)
完整代码如下
package com.auth.actions;
public class SocialAuthSuccessAction extends Action {
final Log LOG = LogFactory.getLog(SocialAuthSuccessAction.class);
@Override
public ActionForward execute(final ActionMapping mapping,
final ActionForm form, final HttpServletRequest request,
final HttpServletResponse response) throws Exception {
AuthForm authForm = (AuthForm) form;
SocialAuthManager manager = null;
if (authForm.getSocialAuthManager() != null) {
manager = authForm.getSocialAuthManager();
}
if (manager != null) {
List<Contact> contactsList = new ArrayList<Contact>();
Profile profile = null;
try {
Map<String, String> paramsMap = new …Run Code Online (Sandbox Code Playgroud) 我有一个约会,如何让所有日期落在给定日期属于java的那一周?
example:
if i give today's date then i should get all dates belonging to this week.
12 July 2015 to 18 July 2015
Run Code Online (Sandbox Code Playgroud)
请有人帮助我.
我想知道给定日期的星期日期,我已解释为什么这个问题不重复,请在评论前阅读.
以下是我发送邮件的代码:
import java.util.Properties;
import javax.mail.Authenticator;
import javax.mail.Message;
import javax.mail.Message.RecipientType;
import javax.mail.MessagingException;
import javax.mail.PasswordAuthentication;
import javax.mail.Session;
import javax.mail.Transport;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;
public class SendMail {
public void sendMail(String m_from,String m_to,String m_subject,String m_body){
try {
Session m_Session;
Message m_simpleMessage;
InternetAddress m_fromAddress;
InternetAddress m_toAddress;
Properties m_properties;
m_properties = new Properties();
m_properties.put("mail.smtp.host", "usdc2spam2.slingmedia.com");
m_properties.put("mail.smtp.socketFactory.port", "465");
m_properties.put("mail.smtp.socketFactory.class","javax.net.ssl.SSLSocketFactory");
m_properties.put("mail.smtp.auth", "true");
m_properties.put("mail.smtp.port", "9000");
m_Session=Session.getDefaultInstance(m_properties,new Authenticator() {
protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication("aaaaa","bbbbb@1"); // username and the password
}
});
m_simpleMessage = new MimeMessage(m_Session);
m_fromAddress = …Run Code Online (Sandbox Code Playgroud)