How to encode properly this URL

I am trying to get this URL using JSoup http://betatruebaonline.com/img/parte/330/CIGUEÑAL.JPG Even using encoding, I got an exception. I don´t understand why the encoding is wrong. It returns http://betatruebaonline.com/img/parte/330/CIGUEN%C3%91AL.JPG instead the correct http://betatruebaonline.com/img/parte/330/CIGUEN%CC%83AL.JPG How I can fix this ? Thanks. private static void

如何正确编码这个URL

我正在尝试使用JSoup来获取此URL http://betatruebaonline.com/img/parte/330/CIGUEÑAL.JPG 即使使用编码,我也有一个例外。 我不明白为什么编码是错误的。 它返回 http://betatruebaonline.com/img/parte/330/CIGUEN%C3%91AL.JPG 而不是正确的 http://betatruebaonline.com/img/parte/330/CIGUEN%CC%83AL.JPG 我如何解决这个问题? 谢谢。 private static void GetUrl() { try { String url = "

Servlet get GET and POST's parameters at the doPost method

My problem is when I'm trying to access a POST Variable with request.getParameter("name") , it works perfectly. But in some conditions, when a POST request arrives at my application, I also need to get GET Parameter from the Query String. As far as I can see, with getParameter , you can only access current request's parameters, but, as in my condition, as I said, I also need

Servlet在doPost方法中获得GET和POST的参数

我的问题是,当我试图通过request.getParameter("name")访问POST变量时,它完美地工作。 但在某些情况下,当POST请求到达我的应用程序时,我还需要从查询字符串中获取GET参数。 就我所知,使用getParameter ,只能访问当前请求的参数,但正如我所说的,正如我所说的,我还需要在doPost方法内获取GET参数。 有没有一种方法来获取GET参数而不解析查询字符串? getParameter()方法可以返回(如果可能的话)GET和PO

are they implementation dependent?

I'm developing Spring Rest webs service using PUT and POST @RequestMapping(value = "/test", method = RequestMethod.POST) @Override public String function(Model model) { } So, what is the difference between using PUT and POST in this case? I know that PUT is idempotent, meaning if the same url is called multiple times, the effect should be the same. If I provide the request method as PUT

它们是否依赖于实现?

我正在使用PUT和POST开发Spring Rest webs服务 @RequestMapping(value = "/test", method = RequestMethod.POST) @Override public String function(Model model) { } 那么,在这种情况下使用PUT和POST有什么区别? 我知道PUT是幂等的,这意味着如果多次调用相同的url,效果应该是相同的。 如果我将请求方法提供为PUT,并且如果在函数内部包含DB操作,PUT的含义将不会发生变化,这意味着如果我多次调用测试URL,则DB值每次

Servlet parameters and doPut

Trying to get parameters from a PUT request using HttpServlet#doPut: public void doPut(HttpServletRequest request, HttpServletResponse response) { String name = request.getParameter("name"); // name is null } Using curl to send the request: curl -X PUT --data "name=batman" --header "Content-Type: text/plain" http://localhost:8080/sample.html works fine with using doGet

Servlet参数和doPut

尝试使用HttpServlet#doPut从PUT请求获取参数: public void doPut(HttpServletRequest request, HttpServletResponse response) { String name = request.getParameter("name"); // name is null } 使用curl发送请求: curl -X PUT --data "name=batman" --header "Content-Type: text/plain" http://localhost:8080/sample.html 使用doGet和GET curl请求可以很好地工作。 我错过了什么吗? 根

Should you synchronize access to properties in Java?

This question already has an answer here: Should getters and setters be synchronized? 4 answers My question is why? To ensure memory visibility across threads. What would be the use of synchronizing getId method? Every synchronized getId call guarantees that the given id is up-to-date for the moment of ending of the operation (releasing a lock). Or what could happen if I don't sy

你应该同步访问Java中的属性吗?

这个问题在这里已经有了答案: getter和setter应该同步吗? 4个答案 我的问题是为什么? 确保跨线程的内存可见性。 什么是同步getId方法的使用? 每次同步的getId调用都会保证给定的id在操作结束的时刻是最新的(释放一个锁)。 或者如果我不同步会发生什么? 一个陈旧的getId值将被用来更新其他影响正确性的变量。 每个使用共享状态变量的方法都需要某种同步。 getter提供状态,所以需要同步。 setter改变状

How to sort duplicated Strings using comparator?

Say i have a list containing workers, each workers has 3 fields: its name, the department he's working in (can be just the name of the department or an Object from the class Department) and his salary. Elvis Software Engineering 1000 Samba Mechanical Engineering 2000 Bamba Industrial Engineering 3000 Bisli Medical Engineering 4000 Kinder

如何使用比较器对重复的字符串进行排序?

假设我有一个包含工人的列表,每个工人都有三个字段:名称,他所在的部门(可以只是部门的名称或班级部门的对象)和他的工资。 Elvis Software Engineering 1000 Samba Mechanical Engineering 2000 Bamba Industrial Engineering 3000 Bisli Medical Engineering 4000 Kinder Electrical Engineering 1000 Elvis Software Engineering 9999 现在我

What is the best way to implement constants in Java?

I've seen examples like this: public class MaxSeconds { public static final int MAX_SECONDS = 25; } and supposed that I could have a Constants class to wrap constants in, declaring them static final. I know practically no Java at all and am wondering if this is the best way to create constants. That is perfectly acceptable, probably even the standard. (public/private) static final TY

在Java中实现常量的最佳方式是什么?

我见过这样的例子: public class MaxSeconds { public static final int MAX_SECONDS = 25; } 并假设我可以有一个Constants类来包装常量,并将它们声明为static final。 我几乎完全不知道Java,并且想知道这是否是创建常量的最佳方式。 这是完全可以接受的,甚至可能是标准。 (public/private) static final TYPE NAME = VALUE; 其中TYPE是类型, NAME是所有大写字母中带空格的下划线的名称, VALUE是常量值; 我强

Idiomatic Gradle script to build 'debug' and 'release' JAR files

I'm trying to create a Gradle build script that will build a Java .jar file in 'release' or 'debug' modes and am having trouble parametrizing the script. The question is: What is an idiomatic way to do this in a Gradle script, using the Java plugin? (or, if there's no idiomatic way, what's a hacky solution that actually works?) I don't mind the method of param

习惯性Gradle脚本构建'debug'和'release'JAR文件

我试图创建一个Gradle构建脚本,它将在'release'或'debug'模式下构建一个Java .jar文件,并且无法参数化脚本。 问题是: 在使用Java插件的Gradle脚本中,通过何种惯用方式来实现这一点? (或者,如果没有惯用的方法,那么实际上有效的黑客解决方案是什么?) 我不介意参数化方法,只要命令行和IDE调用可以在两个输出选项之间轻松选择即可。 该jar文件将在其他项目中用作库,例如Android应用程序和JavaFX

Recursive usage of @Retention annotation , how is it possible?

In the source code of @Retention annotation in java, @Retention is used in its definition itself, hows that possible. Even the RetentionPolicy is set at RUNTIME, so how could it get executed before its not ready to run. package java.lang.annotation; @Documented @Retention(RetentionPolicy.RUNTIME) @Target(ElementType.ANNOTATION_TYPE) public @interface Retention { /** * Returns the ret

@Retention注释的递归使用,它怎么可能?

在java中@Retention注解的源代码中, @Retention被用在它自己的定义中,这是可能的。 即使RetentionPolicy被设置为RUNTIME,那么它在未准备好运行之前如何被执行。 package java.lang.annotation; @Documented @Retention(RetentionPolicy.RUNTIME) @Target(ElementType.ANNOTATION_TYPE) public @interface Retention { /** * Returns the retention policy. * @return the retention policy */ Rete

How do I do a deep copy of a 2d array in Java?

I just got bit by using .clone() on my 2d boolean array, thinking that this was a deep copy. How can I perform a deep copy of my boolean[][] array? Should I loop through it and do a series of System.arraycopy 's? Yes, you should iterate over 2D boolean array in order to deep copy it. Also look at java.util.Arrays#copyOf methods if you are on Java 6. I would suggest the next code for

如何在Java中做一个2d数组的深层副本?

我刚刚在我的2d boolean数组上使用.clone() ,认为这是一个深层复制。 我怎样才能执行我的boolean[][]数组的深层副本? 我是否应该循环执行一系列System.arraycopy ? 是的,您应该迭代2D布尔数组以便深度复制它。 如果您使用Java 6,请查看java.util.Arrays#copyOf方法。 我会建议Java 6的下一个代码: public static boolean[][] deepCopy(boolean[][] original) { if (original == null) { return null;