我正在尝试解决使用AJAX与多部分表单数据的问题.这个页面看起来不错.基本上,您可以将表单提交的输出重定向到iframe,而不是使用AJAX.但是,它并不适合我.这是我的客户端HTML代码:
<form id="submitDocumentForm" target='upload_target' name="submitDocumentForm" enctype="multipart/form-data" action="MyServlet" method="POST">
<input id="inputFile" type="file" name="inputFile"/>
<input type="submit" value="Import Document" />
<iframe id="upload_target" name="upload_target" src="" style="width:100;height:100;border:0px solid #fff;"></iframe>
</form>
Run Code Online (Sandbox Code Playgroud)
服务器端处理似乎工作正常,但客户端响应(IE7)是弹出文件下载"您要保存此文件,还是查找程序..."对话框.这是相关的服务器端Java代码:
//handling of the file and exception handling omitted
JSONObject responseData = new JSONObject();
responseData.put("messages", "Upload complete");
PrintWriter pw = response.getWriter();
response.setHeader(RESP_HEADER_CACHE_CONTROL, RESP_HEADER_VAL_NO_CACHE);
response.setContentType("application/json");
pw.println(responseData.toString());
pw.close();
Run Code Online (Sandbox Code Playgroud)
关于如何解决这个问题的任何建议?提前谢谢了.
我有以下清单(摘要):
<?xml version="1.0" encoding="utf-8"?>
<manifest
xmlns:android="http://schemas.android.com/apk/res/android"
android:versionCode="1"
android:versionName="1.0"
package="com.uniquename.appname">
<application
android:icon="@drawable/ic_launcher_icon"
android:label="@string/app_name"
android:name=".activity.MainApplication">
....
Run Code Online (Sandbox Code Playgroud)
在那里MainApplication.java生活com.uniquename.appname.activity
但是,当我启动它时,出现以下错误:
10-10 23:12:33.327:错误/ AndroidRuntime(7783):java.lang.RuntimeException:无法实例化应用程序com.uniquename.appname.MainApplication:java.lang.ClassNotFoundException:com.uniquename.appname.MainApplication在加载程序dalvik中.system.PathClassLoader [/system/framework/android.test.runner.jar:/data/app/com.uniquename.appname-1.apk]
这让我感到奇怪,因为我已经明确要求它查看活动子包。我已经看到了其他人使用这种相对技术的示例,但是对我来说不起作用。我的声明怎么了?谢谢!
我正在对其他开发人员的 bash 脚本进行质量检查。它看起来像这样:
#!/bin/bash
TERM=`cat ./termName.txt` || exit $?
./other-script.sh $TERM
Run Code Online (Sandbox Code Playgroud)
鉴于该TERM变量未在最后一行中引用,感觉恶意用户可以通过操纵 的内容来利用命令注入termName.txt,但是我证明这一点的基本尝试未能注入任何可执行命令。
我的问题是:
我正在尝试为25到50年前的出生日期编写出生发生器的随机日期.我坚持使用Java 1.4并试图通过java.util.Calendar来实现这一点(是的,是的,我知道我应该使用Joda库).这是我在的地方:
private static long ONE_YEAR_AS_MILLISECONDS = 365*24*60*60*1000;
private static long TWENTY_FIVE_YEARS_AS_MILLISECONDS = 25*ONE_YEAR_AS_MILLISECONDS;
private static long FIFTY_YEARS_AS_MILLISECONDS = 50*ONE_YEAR_AS_MILLISECONDS;
private static String generateDOB()
{
//Equation for calculating a random number within a given range is as follows: Min + (int)(Math.random() * ((Max - Min) + 1))
long someTimeBetween25And50YearsInMilliSeconds = TWENTY_FIVE_YEARS_AS_MILLISECONDS +
(long)(Math.random() * ((FIFTY_YEARS_AS_MILLISECONDS - TWENTY_FIVE_YEARS_AS_MILLISECONDS) + 1));
Calendar dob = Calendar.getInstance();
dob.setTimeInMillis(dob.getTimeInMillis() - someTimeBetween25And50YearsInMilliSeconds);
StringBuffer sb = new StringBuffer();
sb.append(dob.get(Calendar.YEAR)).append("/").append(dob.get(Calendar.MONTH)+1).append("/").append(dob.get(Calendar.DAY_OF_MONTH));
return sb.toString();
}
Run Code Online (Sandbox Code Playgroud)
它执行正常,但在2008年或2009年,100个日期的输出结果全部为:
2008/10/8
2008/9/22
2008/7/26
2008/8/20 …Run Code Online (Sandbox Code Playgroud) 在我的应用程序中,我已经设置了一个位置管理器,每10分钟更新一次当前位置(或者我认为).相反,我每5分钟收到一次更新:
10-03 23:45:17.153: DEBUG/TheApp(2025): Location updated with accuracy: 48.0m
10-03 23:50:23.162: DEBUG/TheApp(2025): Location updated with accuracy: 48.0m
10-03 23:55:23.074: DEBUG/TheApp(2025): Location updated with accuracy: 48.0m
10-04 00:00:23.077: DEBUG/TheApp(2025): Location updated with accuracy: 48.0m
Run Code Online (Sandbox Code Playgroud)
这是代码:
LocationManager locationManager = (LocationManager)
this.getSystemService(Context.LOCATION_SERVICE);
LocationListener locationListener = new LocationListener() {
public void onLocationChanged(Location location) {
Log.d(APP_TAG, "Location updated with accuracy: " + location.getAccuracy() + "m");
}
//Other methods are empty and omitted for brevity
};
int TEN_MINUTES = 10 /*Minutes*/ * 60 /*sec per min*/ …Run Code Online (Sandbox Code Playgroud) 我有以下代码:
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'", Locale.UK);
Instant inst = DateTimeUtils.toInstant(sdf.parse("2019-08-13T18:00:00Z"));
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("HH:mm").withLocale(Locale.UK).withZone(ZoneId.of("Europe/London"));
System.out.println(formatter.format(inst));
//prints 18:00
Run Code Online (Sandbox Code Playgroud)
这让我感到惊讶,因为我认为inst这将是 GMT/UTC 时间,并且formatter会将其格式化为伦敦时间(该日期为 BST(UTC+1:00)),生成19:00.
我在这里缺少什么?
我猜这是我的代码一个通用的问题,但如果它的确与众不同,这是利用org.threeten.bp.*从类ThreeTen-反向移植项目,在另外的适应Android的早期ThreeTenABP项目。
我有以下JAXB解组代码,我试图概括.这是它的样子:
private Object getResponseObject(String stubbedXmlFile,
Class jaxbInterfaceClass,
AbstractRepository repository) {
Object responseObject = null;
try {
JAXBContext jc = JAXBContext.newInstance(jaxbInterfaceClass);
Unmarshaller u = jc.createUnmarshaller();
InputStream resourceAsStream = TestProvidePensionValuationRepository.class.getClassLoader()
.getResourceAsStream(stubbedXmlFile);
BufferedReader br = new BufferedReader(new InputStreamReader(resourceAsStream));
StringBuilder sb = new StringBuilder();
String line;
while ((line = br.readLine()) != null) {
sb.append(line);
}
br.close();
ByteArrayInputStream byteStream =
new ByteArrayInputStream(sb.toString().getBytes());
responseObject = u.unmarshal(byteStream);
} catch (JAXBException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
return responseObject;
}
Run Code Online (Sandbox Code Playgroud)
我的目标不是返回一个Object,而是返回作为参数传入的同一个类(例如jaxbInterfaceClass).我认为这可能与Generics有关,但作为仿制药的相对新手,我很难过.任何帮助赞赏!
我有以下代码用于压缩字符串(为清楚起见,删除了错误和资源处理):
import java.util.zip.GZIP*;
import java.io.*;
import java.util.zip.GZIPOutputStream;
import org.apache.commons.io.IOUtils;
import com.Ostermiller.util.Base64;
//Code to compress the string
ByteArrayOutputStream output = new ByteArrayOutputStream(65536);
BufferedWriter writer = new BufferedWriter(
new OutputStreamWriter(new GZIPOutputStream(output)));
writer.write(stringContents);
String compressedString = new String(Base64.encode(output.toByteArray()));
...
//Code to decompress the string
byte[] compressedData = Base64.decode(compressedString.getBytes());
BufferedInputStream reader = new BufferedInputStream(
new GZIPInputStream(new ByteArrayInputStream(compressedData)));
String uncompressedString = IOUtils.toString(reader, "UTF-8");
Run Code Online (Sandbox Code Playgroud)
我们在尝试编码然后解码其中带有'£'的字符串时遇到错误.具体来说,字符串压缩OK,但在尝试解压缩字符串时,我们得到以下堆栈跟踪:
sun.io.MalformedInputException
at sun.io.ByteToCharUTF8.convert(ByteToCharUTF8.java(Compiled Code))
at sun.nio.cs.StreamDecoder$ConverterSD.convertInto(StreamDecoder.java:287)
at sun.nio.cs.StreamDecoder$ConverterSD.implRead(StreamDecoder.java:337)
at sun.nio.cs.StreamDecoder.read(StreamDecoder.java:223)
at java.io.InputStreamReader.read(InputStreamReader.java:208)
at java.io.Reader.read(Reader.java:113)
at org.apache.commons.io.IOUtils.copyLarge(IOUtils.java:1128)
at org.apache.commons.io.IOUtils.copy(IOUtils.java:1104)
at org.apache.commons.io.IOUtils.copy(IOUtils.java:1078)
at …Run Code Online (Sandbox Code Playgroud) 我有一个像这样的Android SQLite表定义:
create table MyTable(..., myDate integer, ...);
Run Code Online (Sandbox Code Playgroud)
稍后在我的代码中,我查询此表以通过游标检索myDate的值:
long dateInstant = cursor.getLong(cursor.getColumnIndexOrThrow("myDate"));
Run Code Online (Sandbox Code Playgroud)
但是,我想知道这是否是最佳方法.如果未设置该值(即数据库为null),则上述方法返回0,这恰好也是有效值.我需要区分有效值和空值.另外,从javadoc getLong:
结果以及当列值为null时,此方法是否抛出异常,列类型不是整数类型,或者整数值超出范围[Long.MIN_VALUE,Long.MAX_VALUE]是实现定义的.
这似乎表明,如果我正确地读到这一点,那么在未来的某个时刻,Android中提供的SQLite实现可能会选择抛出异常而不是返回0.我正在寻找跨Android版本的一致解决方案.
简而言之,我如何能够以一种允许我区分有效值和null的方式稳健地处理从列中检索整数数据?
java ×4
android ×3
bash ×1
compression ×1
generics ×1
gzip ×1
html ×1
iframe ×1
java-time ×1
javascript ×1
location ×1
nullable ×1
random ×1
security ×1
servlets ×1
sqlite ×1
threetenabp ×1
threetenbp ×1