小编Avi*_*ash的帖子

在Java中使用HTTPS和REST

我有一个用Grizzly制作的REST服务器,它使用HTTPS并与Firefox完美配合.这是代码:

//Build a new Servlet Adapter.
ServletAdapter adapter=new ServletAdapter();
adapter.addInitParameter("com.sun.jersey.config.property.packages", "My.services");
adapter.addInitParameter(ResourceConfig.PROPERTY_CONTAINER_REQUEST_FILTERS, SecurityFilter.class.getName());
adapter.setContextPath("/");
adapter.setServletInstance(new ServletContainer());

//Configure SSL (See instructions at the top of this file on how these files are generated.)
SSLConfig ssl=new SSLConfig();
String keystoreFile=Main.class.getResource("resources/keystore_server.jks").toURI().getPath();
System.out.printf("Using keystore at: %s.",keystoreFile);
ssl.setKeyStoreFile(keystoreFile);
ssl.setKeyStorePass("asdfgh");

//Build the web server.
GrizzlyWebServer webServer=new GrizzlyWebServer(getPort(9999),".",true);

//Add the servlet.
webServer.addGrizzlyAdapter(adapter, new String[]{"/"});

//Set SSL
webServer.setSSLConfig(ssl);

//Start it up.
System.out.println(String.format("Jersey app started with WADL available at "
  + "%sapplication.wadl\n",
        "https://localhost:9999/"));
webServer.start();
Run Code Online (Sandbox Code Playgroud)

现在,我尝试用Java实现它:

SSLContext ctx=null;
try {
    ctx …
Run Code Online (Sandbox Code Playgroud)

java rest ssl x509

32
推荐指数
2
解决办法
10万
查看次数

在Java ConcurrentHashMap中打印所有键/值对

我试图简单地在ConcurrentHashMap中打印所有键/值对.

我在网上找到了这个代码,我认为会这样做,但它似乎是获取有关桶/哈希码的信息.其实说实话输出很奇怪,可能我的程序不正确,但我首先要确保这部分是我想要使用的.

for (Entry<StringBuilder, Integer> entry : wordCountMap.entrySet()) {
    String key = entry.getKey().toString();
    Integer value = entry.getValue();
    System.out.println("key, " + key + " value " + value);
}
Run Code Online (Sandbox Code Playgroud)

这为大约10个不同的键提供输出,其计数似乎是映射到插入的总插入数的总和.

java collections hashmap concurrenthashmap

12
推荐指数
3
解决办法
13万
查看次数

如何检查是否从HTML下拉列表中选择了某个项目?

我有一个drop drown列表,我无法检查是否从下拉列表中选择了一个值

以下是我的HTML代码:

<label class="paylabel" for="cardtype">Card Type:</label>
<select id="cardtype" name="cards">
    <option value="selectcard">--- Please select ---</option>
    <option value="mastercard">Mastercard</option>
    <option value="maestro">Maestro</option>
    <option value="solo">Solo (UK only)</option>
    <option value="visaelectron">Visa Electron</option>
    <option value="visadebit">Visa Debit</option>
</select><br/>
Run Code Online (Sandbox Code Playgroud)

以下是我的JavaScript代码:

var card = document.getElementByName("cards")[0].value;
if (card.value == selectcard) {
    alert("Please select a card type");
}
Run Code Online (Sandbox Code Playgroud)

html javascript html-select drop-down-menu

11
推荐指数
3
解决办法
16万
查看次数

如何修复PHP中的警告非法字符串偏移量

我有一大堆PHP代码给我错误:

警告:非法串偏移'iso_format_recent_works'在 C:\ XAMPP\htdocs中\曼塔\可湿性粉剂内容\主题\曼塔\ functions.php的上线1328

这是警告与之相关的代码:

if(1 == $manta_option['iso_format_recent_works']){
    $theme_img = 'recent_works_thumbnail';
} else {
    $theme_img = 'recent_works_iso_thumbnail';
}
Run Code Online (Sandbox Code Playgroud)

当我做a时,var_dump($manta_option);我收到以下结果:

["iso_format_recent_works"] => string(1)"1"

我试图铸造$manta_option['iso_format_recent_works']一个int,但仍然得到了同样的问题.

任何帮助将不胜感激!

php arrays wordpress casting offset

7
推荐指数
1
解决办法
10万
查看次数

如何从excel 2010中的列中仅删除0(零)值

我想从整个列中删除值,其中单元格值为0.

生成的细胞应为空白.

我该如何为此编写公式?有什么建议?

TELEPHONE NUMBERS
----------
49 5235102027   <-- Cell has 0 value but shouldn't removed!
35 2578945655
0               <-- Remove this   
90 5322720638
48 5396329155
Run Code Online (Sandbox Code Playgroud)

excel-formula excel-2010

6
推荐指数
2
解决办法
21万
查看次数

在Android Marshmallow中启用模拟位置

我无法在Android Marshmallow中使用模拟位置.我在Android 6.0中安装了应用程序.现在,当我想通过以下选项为此应用程序设置模拟位置时.

设置>>开发者选项>>选择模拟位置应用

我看不到任何要选择的应用程序.

有没有人在Marshmallow下成功实现模拟位置?

android unit-testing mocking android-6.0-marshmallow

6
推荐指数
1
解决办法
5万
查看次数

@JsonIgnoreProperties(ignoreUnknown=false) 在 Spring 4.2.0 及更高版本中不起作用

@JsonIgnoreProperties(ignoreUnknown=false) 不适用于 spring 4.2.0 和更高版本的 spring。但它适用于 4.0.4 和 4.0.1 。我正在使用 spring 4.2.8 并使用 Jackson 依赖项

<dependency>
    <groupId>com.fasterxml.jackson.core</groupId>
    <artifactId>jackson-databind</artifactId>
    <version>2.6.3</version>
</dependency>
<dependency>
    <groupId>com.fasterxml.jackson.core</groupId>
    <artifactId>jackson-core</artifactId>
    <version>2.6.3</version>
</dependency>
<dependency>
    <groupId>com.fasterxml.jackson.core</groupId>
    <artifactId>jackson-annotations</artifactId>
    <version>2.6.3</version>
</dependency>
Run Code Online (Sandbox Code Playgroud)

如果我发送带有无效字段的 json 请求,那么它会作为有效请求接受。但它应该给出错误的请求作为响应。例如:如果我有课

public class Student{ 
    private String id; 
    private String name; 
}
Run Code Online (Sandbox Code Playgroud)

如果发送有效的相应 json 请求,它应该是这样的

{ 
   "id": "123", 
   "name": "test" 
}
Run Code Online (Sandbox Code Playgroud)

但即使我发送带有无效字段的 json 请求,如下所示,它仍然接受。

{ 
    "id": "123", 
    "name": "test", 
    "anyinvalidkey": "test" 
}
Run Code Online (Sandbox Code Playgroud)

但它应该给出错误的请求作为响应

spring spring-mvc jackson-dataformat-xml jackson2

6
推荐指数
2
解决办法
8308
查看次数

通过onclick事件调用php函数

我试图通过按钮的"onclick"事件来调用函数.当我这样做时,它显示错误消息.任何人都可以帮我解决这个问题,这样当我点击按钮时它应该调用该函数并执行它.

我的PHP代码是:

<?php
    function hello() {
        echo "Hello";
    }
    echo "<input type='button' name='Release' onclick= hello(); value='Click to Release'>";
?>
Run Code Online (Sandbox Code Playgroud)

这段代码有什么问题?

php function

5
推荐指数
2
解决办法
18万
查看次数

成功提交php表单后清除表单字段

我正在制作一个简单的表格,我面临的问题是,当我提交表格时,价值仍然存在于现场.我想在SUCCESSFUL提交后清除它.请帮忙.

这是我的表格代码..

<label class="w">Plan :</label>
<select autofocus="" name="plan" required="required">
    <option value="">Select One</option>
    <option value="FREE Account">FREE Account</option>
    <option value="Premium Account Monthly">Premium Account Monthly</option>
    <option value="Premium Account Yearly">Premium Account Yearly</option>
</select>
<br>
<label class="w">First Name :</label><input name="firstname" type="text" placeholder="First Name" required="required" value="<?php echo $_POST['firstname'];?>"><br>
<label class="w">Last Name :</label><input name="lastname" type="text" placeholder="Last Name" required="required" value="<?php echo $_POST['lastname'];?>"><br>
<label class="w">E-mail ID :</label><input name="email" type="email" placeholder="Enter Email" required="required" value="<?php echo $_POST['email'];?>"><br>
<label class="w">Password :</label><input name="password" type="password" placeholder="********" required="required" value="<?php echo $_POST['password'];?>"><br>
<label class="w">Re-Enter Password :</label><input …
Run Code Online (Sandbox Code Playgroud)

php forms

4
推荐指数
2
解决办法
13万
查看次数

Spring启动示例:无法启动嵌入式容器错误

我是春天的新手,所以我从spring intializr下载jar用于maven-web java 1.8 demo.我解压缩并将其导入STS以运行main()文件,然后我得到以下异常.有人可以告诉我这是什么解决方案吗?

解决方案我尝试从网络但没有工作: - 尝试将Hibernate验证器依赖添加到pom - 尝试将spring-boot-starter-tomcat依赖添加到pom

堆栈跟踪:

2017-01-26 12:19:32.587  INFO 3816 --- [           main] ationConfigEmbeddedWebApplicationContext : Refreshing org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext@2e4b8173: startup date [Thu Jan 26 12:19:32 EST 2017]; root of context hierarchy
2017-01-26 12:19:36.442  WARN 3816 --- [           main] ationConfigEmbeddedWebApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.context.ApplicationContextException: Unable to start embedded container; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'tomcatEmbeddedServletContainerFactory' defined in class path resource [org/springframework/boot/autoconfigure/web/EmbeddedServletContainerAutoConfiguration$EmbeddedTomcat.class]: Initialization of bean failed; nested …
Run Code Online (Sandbox Code Playgroud)

spring spring-boot

3
推荐指数
1
解决办法
1万
查看次数

PM2日志文件的默认位置是什么?

我试图找出PM2默认将日志文件保存在哪里?

我正在使用Linux Ubuntu 16.04服务器,并使用进行了全局安装npm i pm2 -g

ubuntu node.js npm pm2

3
推荐指数
5
解决办法
2060
查看次数