XmlMapper xmlMapper = new XmlMapper();
SomeClass obj = xmlMapper.readValue(xmlStr, SimpleBean.class);
JAXBContext jaxbContext = JAXBContext.newInstance(SomeClass.class);
Unmarshaller unmarshaller = jaxbContext.createUnmarshaller();
StreamSource source = new StreamSource(new StringReader(xmlStr));
JAXBElement<SomeClass> element = unmarshaller.unmarshal(source, SomeClass.class);
SomeClass someClass = element.getValue();
private ResultSet fetchRows() {
...
}
private JSONObject toJson(ResultSet rows) {
...
}
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
response.setContentType("application/json");
response.setCharacterEncoding("UTF-8");
try (PrintWriter out = response.getWriter()) {
out.append(toJson(fetchRows()));
}
}
<div id="output"></div>
<button id="button">Нажми меня</button>
var output = document.getElementById('output');
var button = document.getElementById('button');
var xhr = new XMLHttpRequest();
xhr.onreadystatechange = function() {
if (xhr.readyState != 4) return;
if (xhr.status == 200) {
data = JSON.parse(xhr.responseText);
response = ['<table>', '<tr><th>Имя</th><th>Фамилия</th></tr>'];
for (var x = 0; x < data.persons.length; x++) {
response.push('<tr>');
response.push('<td>' + data.persons[x].firstName + '</td>');
response.push('<td>' + data.persons[x].lastName + '</td>');
response.push('</tr>');
}
response.push('</table>');
output.innerHTML = response.join('');
}
else {
alert('Ошибка! ' + xhr.statusText);
}
button.innerHTML = 'Нажми меня';
button.disabled = false;
};
button.addEventListener('click', function(event) {
this.innerHTML = 'Загружаю...';
this.disabled = true;
xhr.open('POST', '/some/servlet/url', true);
xhr.send();
});
import io.netty.util.Timer;
import io.netty.util.TimerTask;
timer.newTimeout(new TimerTask() {
@Override
public void run(Timeout timeout) throws Exception {
// Отложенное действие
}
}, 30, TimeUnit.SECONDS);
eventLoop.schedule(() -> {
// Отложенное действие
}, 30, TimeUnit.MILLISECONDS);
new ServerBootstrap().group(group)
.channel(NioServerSocketChannel.class)
.childHandler(new ChannelInitializer<SocketChannel>() {
@Override
public void initChannel(SocketChannel socketChannel) {
final long startTime = System.currentTimeMillis();
ChannelPipeline pipeline = socketChannel.pipeline();
pipeline.addLast(new ChannelOutboundHandlerAdapter() {
@Override
public void read(ChannelHandlerContext ctx) {
ctx.writeAndFlush(Unpooled.wrappedBuffer("Hello!".getBytes()));
.addListener(ChannelFutureListener.CLOSE);
}
});
ChannelFuture f = socketChannel.closeFuture();
f.addListener(new ChannelFutureListener() {
@Override
public void operationComplete(ChannelFuture future) throws Exception {
System.out.println(System.currentTimeMillis() - startTime);
}
});
}
})
.bind("localhost", 1025)
.sync()
.channel()
.closeFuture()
.syncUninterruptibly();
Map
надо подставить java.util.Map
. После компиляции в байткоде остаются только полные имена классов, директивы import не сохраняются, и никакого дополнительного кода в результирующий объектный модуль не загружается.