Web 开发问题汇总(三)
1.How to send email in java?
A:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
|
Reference:Java - Sending Email
Send email using java
2.Eclipse error: ‘Failed to create the Java Virtual Machine’
A:安装了 Eclipse 提示的升级后再重新打开时,出现上面的报错。Google 一圈后显示可能是 eclipse.ini 的锅,正好我安装了 cpp, java 和 jee 三个版本,尝试打开 java 版本的,正常打开,于是对比它们的 eclipse.ini 文件:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
|
总共有五处不同,细看之后发现只有两处可能会产生影响,先尝试将 -Xms512m
改成 -Xms256m
,问题仍然存在,将文件恢复原样,再尝试将
1 2 3 4 5 6 |
|
删除,问题顺利解决。
Reference:Eclipse error: ‘Failed to create the Java Virtual Machine’
3.Warning: mysqli::__construct(): (HY000/2002): No such file or directory in /code/index.php on line 8 Connection failed: No such file or directory
A:问题出现的原因: 当主机填写为localhost时MySQL会采用 unix domain socket连接,当主机填写为127.0.0.1时MySQL会采用TCP/IP的方式连接。使用Unix socket的连接比TCP/IP的连接更加快速与安全。这是MySQL连接的特性,可以参考官方文档的说明4.2.2. Connecting to the MySQL Server:
On Unix, MySQL programs treat the host name localhost specially, in a way that is likely different from what you expect compared to other network-based programs. For connections to localhost, MySQL programs attempt to connect to the local server by using a Unix socket file. This occurs even if a –port or -P option is given to specify a port number. To ensure that the client makes a TCP/IP connection to the local server, use –host or -h to specify a host name value of 127.0.0.1, or the IP address or name of the local server. You can also specify the connection protocol explicitly, even for localhost, by using the –protocol=TCP option.
这个问题有以下几种解决方法:
- 使用TCP/IP代替Unix socket。即在连接的时候将localhost换成127.0.0.1。
- 修改MySQL的配置文件my.cnf,指定mysql.socket的位置: /var/lib/mysql/mysql.sock (你的mysql.socket路径)。
- 直接在php建立连接的时候指定my.socket的位置(官方文档:mysqli_connect)。比如:
$db = new MySQLi('localhost', 'root', 'root', 'my_db', '3306', '/var/run/mysqld/mysqld.sock')
Reference:mysqli不能使用localhost,请问这是怎么回事?
4.超链接元素的 onclick 方法直接使用表单元素的名字调用其 submit 方法。
A:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
|
这里展示了可以直接使用表单元素的名字直接来提交的技巧。
5.Ionic - Cannot find module “.”
A:Just remove all imports that have /umd at the final.
In my case, I changed:
import { IonicPageModule } from 'ionic-angular/umd';
To:
import { IonicPageModule } from 'ionic-angular';
Reference:Ionic 2 - Runtime error Cannot find module “.”
6.Google maps report google is not define in ionic app.
A:
- go to your project and do “ionic plugin add cordova-plugin-whitelist”
- add CSP meta
1
|
|
Live reload unfortunately seems not work, I get this error:
1
|
|
After some google, update CSP meta works, new CSP meta as follow:
1
|
|
Reference:Ionic + Google Maps: ReferenceError: google is not defined
Solution for livereload problems with new CSP rules
7.Error: No provider for Navbar!
A:Normally navbar don’t provide with injector, we should access like follow:
1 2 3 4 5 6 7 8 9 |
|
1 2 3 4 5 6 |
|
Reference:Error in ./HomePage class HomePage - caused by: No provider for Navbar!
8.How to custom back button of ionic app?
A:
1 2 3 4 5 6 7 8 9 10 |
|
Reference:Change default ion-navbar “back” button ios
9.How to make a div take the remaining height?
A:
- Absolute Positioning
- Tables
- CSS3 calc
Absolute Positioning
1 2 3 4 5 6 7 8 |
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
|
pros
- easy to implement
- intuitive
cons
- tedious to maintain (hard-coded positions)
Tables
1 2 3 4 5 6 7 8 9 10 |
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
|
pros
- rather “clean” solution
- no hard-coded values, other elements can change their height
cons
- might cause some side-effects with the layout
CSS3 calc
1 2 3 4 5 6 7 8 |
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
|
pros
- easy to implement
- less code than the other solutions
cons
- the calc function is rather new (no support for older browsers)
- tedious to maintain (hard-coded height)
Reference:How to make a div take the remaining height
10.Property ‘of’ does not exist on type ‘typeof Observable
A: for Angular >= 6.0.0 uses RxJS 6.0.0
1
|
|
And its usage has been changed, you no longer call it off of Observable:
1
|
|
for Angular <= 5.x.xx
1 2 3 |
|
Reference:Property ‘of’ does not exist on type ‘typeof Observable
11.class path resource [keystore.jks ] cannot be resolved to URL because it does not exist
A:Reason is that a space appended to end. Remove end space in application.properties works. I confirm keystore.jks is in target classes, but runtime complain can’t find it. why? After some google, still not found right solution, suddenly I notice there a space at end, may be that is the reason. Fact show my doubt is right.
12.How to pass program argument start with two hyphen(dash) to java in eclipse?
A:Run > Debug Configurations… > Arguments > Right click in the text field, deselect “Substitutions” > “Smart Dashes”
Reference:Double dash in “Program argument” of “Run configurations” becomes “\u2014”
13.How to find out what auto-configuration is currently being applied by Spring Boot?
A:If you need to find out what auto-configuration is currently being applied, and why, start your application with the –debug switch. For example:
1
|
|
I also find we can enable debug property archive this goal.
1 2 |
|
14.How to search files inside source jars in eclipse?
A:Recently discovered the following plugin has beta support for searching into linked source jars: eclipse-instasearch
You have to enable searching source jars in the preferences as it is turned off by default.To enable searching in jars, go to Window > Preferences > General > Search > InstaSearch and select the option that says “Index JAR source attachments (beta)” .
Depending on how much source you have, the indexing process is very slow, but then search is very fast.
Reference:How to make eclipse “File Search” to also search inside source jars containing some text?
15.How to get Pseudo-Element properties with JavaScript?
A:Assume your CSS looks like:
1 2 3 4 |
|
To retrieve the color property of the .element:before
, you could use the following JavaScript:
1 2 3 4 5 6 7 |
|