IDEA配置和常见问题
解决方式来自于网络
1. Junit中无法获取控制台输入
- 1)进入help->Edit Custom VM Options
- 2)添加:
-Deditable.java.test.console=true
- 3)重启IDEA
- 点击File–>Invalidate Caches进入重启窗口
- 择重启方式,四个按钮,一共三种重启方式:
- ① Invalidate and Restart 清空缓存并重启。
- ② Invalidate 清除缓存,下次打开重启。
- ③ Cancel 取消。
- ④ Just Restart 重启。
2. 一个程序如何run多个?
- 1)在idea右上角启动按钮左边,选择
Edit Configurations...
- 2)在Name(最上面)一栏,选择
Allow parallel run
3. 连接数据库时出现的异常
① 异常1:
Loading class ‘com.mysql.jdbc.Driver’. This is deprecated. The new driver class is `com.mysql.cj.jdbc.Driver’. The driver is automatically registered via the SPI and manual loading of the driver class is generally unnecessary.
- 出现问题原因:使用了最新的驱动
- 解决办法:
- 将原先的注册方式:
Class.forName("com.mysql.jdbc.Driver");
- 改为:
Class.forName("com.mysql.cj.jdbc.Driver");
- 将原先的注册方式:
② 异常2:
java.sql.SQLException: The server time zone value ‘�й���ʱ��’ is unrecognized or represents more that…
- 出现问题原因:在使用mysql的jdbc驱动最新版(8.0+)时,遇到数据库和系统时区差异引起的问题。
- 解决办法:在url后添加:
?serverTimezone = GMT
- 例如:
Connection conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/girls?serverTimezone = GMT", "root", "root");
- 例如:
4. Tomcat启动乱码
-
出现问题原因:系统编码为GB2312,而Tomcat的编码为UTF-8。
- cmd中输入:
chcp
查看,代码936对应GB2312
- cmd中输入:
-
解决办法:修改
conf/logging.xml
中的java.util.logging.ConsoleHandler.encoding = GBK
5.IDEA中无法导入Servlet的包
解决办法:
-
1)File — Project Structure
- 如图所示:
- 如图所示:
-
2)如图所示:
-
6. Java Web项目中添加静态资源未加载进服务器
- 问题描述:在 Java Web项目中的web下创建images文件夹并添加图片后,启动服务器。服务器访问不到该目录下的图片。经查询,该新建文件夹及图片未被部署到服务器中。
- 解决办法:先启动服务器,在创建文件夹,添加图片