java web小問題總結(jié)


title: java web小問題總結(jié)
tags: java,web,小問題
grammar_cjkRuby: true


1編碼格式混亂的問題

get請(qǐng)求亂碼

找到tomcat server.xml 修改Connector 加入U(xiǎn)RIEncoding="utf-8"

<Connector URIEncoding="utf-8"
               port="8080" protocol="HTTP/1.1"
               connectionTimeout="20000"
               redirectPort="8443" />

mysql數(shù)據(jù)庫亂碼
臨時(shí)更改編碼格式,實(shí)際需要到相配置文件相應(yīng)修改

show variables like '%char%';

set character_set_server=utf8;

post請(qǐng)求亂碼,使用spring默認(rèn)過濾器配置

<!-- 統(tǒng)一處理前端post數(shù)據(jù)到后端亂碼的問題 -->
    <filter>
        <filter-name>encodingFilter</filter-name>
        <filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
        <init-param>
            <param-name>encoding</param-name>
            <param-value>UTF-8</param-value>
        </init-param>
    </filter>
    <filter-mapping>
        <filter-name>encodingFilter</filter-name>
        <url-pattern>/*</url-pattern>
    </filter-mapping>

2 調(diào)試模式找不到源文件了

enter description here
enter description here

這是因?yàn)槲覀兪褂昧藅omcat插件進(jìn)行的調(diào)試的,初次debug模式找到不到源文件
按如下教程刪除默認(rèn)的default設(shè)置在點(diǎn)擊添加project,勾選當(dāng)前調(diào)試工程。退出eclipse后就正常了
eclipse調(diào)試之edit source lookup path解決方案


3 Maven 工程編譯報(bào)錯(cuò) Dynamic Web Module 3.0 requires Java 1.6 or newer

網(wǎng)上找了很多的教程發(fā)現(xiàn)都不行查看官方文檔

Description Resource    Path    Location    Type
Dynamic Web Module 3.0 requires Java 1.6 or newer.  clouddisk       line 1  Maven Java EE Configuration Problem
Description Resource    Path    Location    Type
One or more constraints have not been satisfied.    clouddisk       line 1  Maven Java EE Configuration Problem

原來Java web3.0之后默認(rèn)的java編譯工具為 javax.tools.JavaCompiler,而且他的默認(rèn)設(shè)置是jdk1.5版本的。所以我們使用maven插件 Maven Compiler Plugin來編譯maven項(xiàng)目

4 Apache Maven Compiler Plugin

==The Compiler Plugin is used to compile the sources of your project. Since 3.0, the default compiler is javax.tools.JavaCompiler (if you are using java 1.6) and is used to compile Java sources. If you want to force the plugin using javac, you must configure the plugin option forceJavacCompilerUse.
Also note that at present the default source setting is 1.5 and the default target setting is 1.5, independently of the JDK you run Maven with. If you want to change these defaults, you should set source and target as described in Setting the -source and -target of the Java Compiler.
Other compilers than javac can be used and work has already started on AspectJ, .NET, and C#.==

修改pom.xml

<pluginManagement>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>3.6.0</version>
            <configuration>
                <!-- 根據(jù)自己電腦jdk版本設(shè)置 -->
                <source>1.8</source>
                <target>1.8</target>
            </configuration>
        </plugin>
    </plugins>
</pluginManagement> 

Build Path > Java Compiler 然后設(shè)置java編譯版本為1.8

enter description here
enter description here

最后不要忘了Maven->update Project 或者直接快捷鍵 alt+F5
如果還沒有生效就 project->clean一下

enter description here
enter description here

5 瀏覽器 js,css 緩存問題處理

eclipse 上編輯js或者是css文件保存后,刷新chrome瀏覽器,發(fā)現(xiàn)新更改的文件沒有生效,還是用的老的js或者是css文件。這個(gè)時(shí)候就要在啟動(dòng)調(diào)試模式后(F12)刷新界面的時(shí)候選中network 下面的css,js右鍵選擇刪除緩存文件這樣就可以了。。。。

enter description here
enter description here

6 java Date SimpleDateFormat 轉(zhuǎn)換

隨機(jī)出一個(gè)給定時(shí)間段內(nèi)的的時(shí)間

SimpleDateFormat SIMPLE_DATE_FORMAT = new SimpleDateFormat("yyyy-MM-dd");

private String randomDate(String beginDate,String endDate) {
      try {
          Date bDate = SIMPLE_DATE_FORMAT.parse(beginDate);
          Date eDate = SIMPLE_DATE_FORMAT.parse(endDate);
          
          long randombound = eDate.getTime() - bDate.getTime();
          long randomDis = (long)(Math.random() * randombound);
          long randomDate = bDate.getTime() + randomDis;
          Date resultDate = new Date(randomDate);
          return SIMPLE_DATE_FORMAT.format(resultDate);
      } catch (ParseException e) {
          e.printStackTrace();
      }
      
      return null;
  }
  // 調(diào)用獲取時(shí)間字符串
  String startTime = randomDate("2015-05-01","2017-10-09");
  
  
  String endTime = "2015-05-01";
//  隨機(jī)3-40天后的時(shí)間字符串
  Calendar calendar = new GregorianCalendar();
  calendar.setTime(SIMPLE_DATE_FORMAT.parse(endTime));
  calendar.add(calendar.DATE, 3 + RANDOM.nextInt(40 - 3));
  endTime = SIMPLE_DATE_FORMAT.format(calendar.getTime());

7 windows 右鍵沒有新建操作了

直接win+r輸入如下指令,直接搞定

cmd /k reg add "HKEY_CLASSES_ROOT\Directory\Background\shellex\ContextMenuHandlers\New" /ve /t REG_SZ /d {D969A300-E7FF-11d0-A93B-00A0C90F2719} /f

8 在Eclipse中檢出Maven工程,一直報(bào)這個(gè)錯(cuò):“Missing artifact jdk.tools:jdk.tools:jar:1.7”

<dependency>  
    <groupId>jdk.tools</groupId>  
    <artifactId>jdk.tools</artifactId>  
    <version>1.6</version>  
    <scope>system</scope>  
    <systemPath>C:\Program Files\Java\jdk1.8.0_66/lib/tools.jar</systemPath>  
</dependency>  

9 JAVA錯(cuò)誤: 找不到或無法加載主類

如果是使用maven報(bào)的錯(cuò)誤,留意下面的problems上面的報(bào)錯(cuò)信息,查看一下當(dāng)前工程的報(bào)錯(cuò)可能是某個(gè)庫下載有問題,把那個(gè)路徑下的庫刪除了,重新maven update即可

10 包依賴沖,是可以設(shè)置修改 dependency的順序,例如 hadoop依賴的一個(gè)包的版本比較低,而上面的依賴的版本比較高就會(huì)出問題

11 關(guān)于eclipse 配置maven插件的問題

新安裝Eclipse時(shí),配置自己的maven3.5.0 時(shí),一旦修改默認(rèn)的conf/setting設(shè)置就會(huì)連quick-startMaven模板都創(chuàng)建失敗,這是因?yàn)閙aven的鏡像地址已經(jīng)一直連不上了,必須修改鏡像地址如下,另新版本Eclipse已經(jīng)默認(rèn)安裝了Maven插件因此不需要卸載在安裝了

<mirror>
    <id>nexus-aliyun</id>
    <mirrorOf>*</mirrorOf>
    <name>Nexus aliyun</name>
    <url>http://maven.aliyun.com/nexus/content/groups/public</url>
</mirror> 
  
enter description here
enter description here
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容