Title: Accessing static resources in the javaweb project in idea, importing jar, java.lang.ClassNotFoundException: com.mysql.jdbc.Driver appears
Although maven is used now, take a look at the explanation below, you can deepen your understanding of what maven has done for us
1. For java.lang.ClassNotFoundException: com.mysql.jdbc.Driver,
Generally, it is because you imported the jar, but it is not associated with the module, or it is not redeployed to the project
-
1. If our lib is under Project,
-
- 1.1 First right click lib and then, add as libraries
-
- 1.2 Then connect to the Module [click +, library, then join]
-
- 1.3 Redeploy the project [first click -, then click +]
-
If our lib is under the Module, there is no need to do the above, and you can also follow the above.
-
2. If it is a web project, it needs to be deployed to tomcat at the end
-
- 1. Click ➖
-
- 2. Click + to select artifact
-
-
- 3. Click Apply
3. Note: Our application context should correspond to the one in the url
-
eg: application context is: /, then the url can only be http://locahost:8080/XXX.html, [this html is any html under your web folder, you can also replace XXX.html with aa/ bb/XXX.html]
-
But if your application context is /pro09, then the url should be http://localhost:8080/pro09/xxx.html, which must be corresponding, otherwise, the url cannot be accessed when it automatically jumps
If this is /, it cannot be accessed
2. Import jar as above
3. Access static resources in javaweb project
eg: Access css/index.css, [index.css is in web/css/index.css] There is no problem at all, but it may not be accessible.
- The reason may be: your css was added later and has not been deployed to the project, so you can redeploy it to the project or delete everything under the out folder (it will be regenerated every time you run it) [see above Deploy to the project].
+