<html>
<head>
<meta name="_csrf" content="${_csrf.token}"/>
<meta name="_csrf_header" content="${_csrf.headerName}"/>
...
</head>
...
</html>
var csrfHeaderName = "X-CSRF-TOKEN";
var csrfTokenValue;
var metaTags = document.getElementsByTagName('meta');
for(var i = 0; i < metaTags.length; i++) {
var metaTagName = metaTags[i].getAttribute("name");
if(metaTagName === "_csrf_header")
csrfHeaderName = metaTags[i].getAttribute("content");
if(metaTagName === "_csrf")
csrfTokenValue = metaTags[i].getAttribute("content");
}
...
var xhr = new XMLHttpRequest();
xhr.open("POST", "userChangeTariff?tariffId=" + num1 + "&contractNumber=" + num2, false);
xhr.setRequestHeader(csrfHeaderName, csrfTokenValue);
xhr.send();
@RequestMapping(value = "/adminNewClient", method = RequestMethod.DELETE)
public @ResponseBody Map adminNewClientPost(HttpServletResponse response, HttpServletRequest request,
@RequestParam(value = "name") String name,
@RequestParam(value = "surName") String secondName,
@RequestParam(value = "birthday") String birthdayDate,
@RequestParam(value = "passport") String passport,
@RequestParam(value = "adress") String adress,
@RequestParam(value = "email") String eMail,
@RequestParam(value = "number") String number) {
LinkedHashMap result = new LinkedHashMap();
result.put("nameStat","YES!");
return result;
}
<tr>
<td><input id="surName" type="text" class="form-control" placeholder="Surname"></td>
<td><span style="color:blue;" id="nameStat">${nameStat}</span></td>
</tr>
function popBox() {
x = confirm('Are you sure? ');
if (x == true) {
var xhr = new XMLHttpRequest();
xhr.onload = function(){
var jsonResponse = JSON.parse(this.responseText);
for(var index in jsonResponse) {
if (jsonResponse.hasOwnProperty(index)) {
document.getElementById(index).innerText = jsonResponse[index];
}
}
};
xhr.open("DELETE", "adminNewClient?name=" + name + "&surName=" + surName
+ "&birthday=" + birthday + "&passport=" + passport
+ "&adress=" + adress + "&email=" + email + "&number=" + number, false);
xhr.send();
}
}
Map<String, List<String>> mapOfList = new TreeMap<>();
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>19.0</version>
</dependency>
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<version>1.4.192</version>
</dependency>
import java.sql.*;
public class H2Main {
static {
try {
Class.forName("org.h2.Driver");
} catch (ClassNotFoundException e) {
System.err.println("Error load H2 JDBC driver: " + e.getMessage());
}
}
public static void main(String[] args) {
try (Connection con = DriverManager.getConnection("jdbc:h2:./h2example", "sa", "")) {
createSimpleDBSchema(con);
System.out.printf("Message from H2: %s\n", getMessage(con));
} catch (Exception e) {
System.err.printf("%s: %s\n", e.getClass().getSimpleName(), e.getMessage());
}
}
static void createSimpleDBSchema(Connection con) {
try (Statement stmt = con.createStatement()) {
stmt.executeUpdate("CREATE TABLE HelloH2 (message varchar(255) NULL);");
stmt.executeUpdate("INSERT INTO HelloH2 (message) VALUES ('Hello World!')");
} catch (SQLException e) {
System.err.printf("%s: %s\n", e.getClass().getSimpleName(), e.getMessage());
}
}
static String getMessage(Connection con) throws SQLException {
try (Statement stmt = con.createStatement();
ResultSet rs = stmt.executeQuery("SELECT message FROM HelloH2")) {
if (rs.next())
return rs.getString("message");
else
return null;
}
}
}
The iterators returned by this class's iterator and listIterator methods are fail-fast: if the list is structurally modified at any time after the iterator is created, in any way except through the iterator's own remove or add methods, the iterator will throw a ConcurrentModificationException. Thus, in the face of concurrent modification, the iterator fails quickly and cleanly, rather than risking arbitrary, non-deterministic behavior at an undetermined time in the future.
List<String> names = ....
Iterator<String> i = names.iterator();
while (i.hasNext()) {
String s = i.next(); // must be called before you can call i.remove()
// Do something
i.remove();
}
import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;
import java.math.BigDecimal;
import java.sql.*;
public final class PostgresDriverProxyRegister implements InvocationHandler {
static {
try {
DriverManager.registerDriver((Driver) newProxy(new org.postgresql.Driver()));
} catch (SQLException e) {
e.printStackTrace();
}
}
public static Object newProxy(Object target) {
Class<?> clazz = defineInterface(target);
return clazz == null ? target
: Proxy.newProxyInstance(Driver.class.getClassLoader(), new Class[]{clazz}, new PostgresDriverProxyRegister(target));
}
public static Class<?> defineInterface(Object o) {
if (o == null)
return null;
if (o instanceof Driver)
return Driver.class;
if (o instanceof Connection)
return Connection.class;
if (o instanceof Statement)
return Statement.class;
if (o instanceof PreparedStatement)
return PreparedStatement.class;
if (o instanceof ResultSet)
return ResultSet.class;
return null;
}
private final Object target;
private PostgresDriverProxyRegister(Object target) {
this.target = target;
}
@Override
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
String methodName = method.getName();
// в этом блоки можно делать нужные изменения для возвращаемых значений методамы ResultSet
if (proxy instanceof ResultSet) {
Object invokeResult = method.invoke(target, args);
if (invokeResult != null) {
if ("getBigDecimal".equals(methodName)) {
// округляем до 2-х знаков после запятой
BigDecimal bigDecimal = (BigDecimal) invokeResult;
invokeResult = bigDecimal.setScale(2, BigDecimal.ROUND_HALF_UP);
} else if ("getString".equals(methodName)) {
// убираем пробелы в начале и конце строки, делаем строку в верхнем регистре
String s = (String) invokeResult;
invokeResult = s.trim().toUpperCase();
}
}
return invokeResult;
}
if (proxy instanceof Driver) {
if ("acceptsURL".equals(methodName) || "connect".equals(methodName)) {
// меняем префикс на оригинал
String url = (String) args[0];
if (url.startsWith("jdbc:postgresql-proxy:")) {
args[0] = url.replace("jdbc:postgresql-proxy:", "jdbc:postgresql:");
}
}
}
return invokeAndProxy(method, args);
}
public Object invokeAndProxy(Method method, Object[] args) throws Throwable {
Object returnValue = method.invoke(target, args);
return newProxy(returnValue);
}
}
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;
public class Main {
public static void main(String[] args) throws Exception {
Class.forName("ua.home.jdbc.driver.warp.postgres.PostgresDriverProxyRegister");
try(Connection connection = DriverManager
// используем отличный от оригинала прификс к url 'jdbc:postgresql-proxy:', что бы именно наш драйвер грузился
.getConnection("jdbc:postgresql-proxy://localhost:5432/test_db", "test_user", "test_password");
Statement statement = connection.createStatement();
ResultSet rs = statement.executeQuery("SELECT 12.65456161 as testDecimal, ' tEsTsTrinG ' as testString")) {
if (rs.next()) {
System.out.printf("testDecimal = '%s'\n", rs.getBigDecimal("testDecimal"));
System.out.printf("testString = '%s'\n", rs.getString("testString"));
}
/* output in console
testDecimal = '12.65'
testString = 'TESTSTRING'
*/
}
}
}