美文网首页
java web小问题总结

java web小问题总结

作者: 天堂宝宝_V | 来源:发表于2017-06-13 20:52 被阅读107次

    title: java web小问题总结
    tags: java,web,小问题
    grammar_cjkRuby: true


    1编码格式混乱的问题

    get请求乱码

    找到tomcat server.xml 修改Connector 加入URIEncoding="utf-8"

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

    mysql数据库乱码
    临时更改编码格式,实际需要到相配置文件相应修改

    show variables like '%char%';
    
    set character_set_server=utf8;
    

    post请求乱码,使用spring默认过滤器配置

    <!-- 统一处理前端post数据到后端乱码的问题 -->
        <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 调试模式找不到源文件了

    enter description hereenter description here
    这是因为我们使用了tomcat插件进行的调试的,初次debug模式找到不到源文件
    按如下教程删除默认的default设置在点击添加project,勾选当前调试工程。退出eclipse后就正常了
    eclipse调试之edit source lookup path解决方案

    3 Maven 工程编译报错 Dynamic Web Module 3.0 requires Java 1.6 or newer

    网上找了很多的教程发现都不行查看官方文档

    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之后默认的java编译工具为 javax.tools.JavaCompiler,而且他的默认设置是jdk1.5版本的。所以我们使用maven插件 Maven Compiler Plugin来编译maven项目

    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>
                    <!-- 根据自己电脑jdk版本设置 -->
                    <source>1.8</source>
                    <target>1.8</target>
                </configuration>
            </plugin>
        </plugins>
    </pluginManagement> 
    

    Build Path > Java Compiler 然后设置java编译版本为1.8

    enter description hereenter description here

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

    enter description hereenter description here

    5 浏览器 js,css 缓存问题处理

    eclipse 上编辑js或者是css文件保存后,刷新chrome浏览器,发现新更改的文件没有生效,还是用的老的js或者是css文件。这个时候就要在启动调试模式后(F12)刷新界面的时候选中network 下面的cssjs右键选择删除缓存文件这样就可以了。。。。

    enter description hereenter description here

    6 java Date SimpleDateFormat 转换

    随机出一个给定时间段内的的时间

    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;
      }
      // 调用获取时间字符串
      String startTime = randomDate("2015-05-01","2017-10-09");
      
      
      String endTime = "2015-05-01";
    //  随机3-40天后的时间字符串
      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工程,一直报这个错:“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错误: 找不到或无法加载主类

    如果是使用maven报的错误,留意下面的problems上面的报错信息,查看一下当前工程的报错可能是某个库下载有问题,把那个路径下的库删除了,重新maven update即可

    10 包依赖冲,是可以设置修改 dependency的顺序,例如 hadoop依赖的一个包的版本比较低,而上面的依赖的版本比较高就会出问题

    11 关于eclipse 配置maven插件的问题

    新安装Eclipse时,配置自己的maven3.5.0 时,一旦修改默认的conf/setting设置就会连quick-startMaven模板都创建失败,这是因为maven的镜像地址已经一直连不上了,必须修改镜像地址如下,另新版本Eclipse已经默认安装了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 hereenter description here

    相关文章

      网友评论

          本文标题: java web小问题总结

          本文链接:https://www.haomeiwen.com/subject/vejjqxtx.html