| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 991 人关注过本帖
标题:jsp页面调用js脚本文件如何解决乱码问题
只看楼主 加入收藏
cmjztt
Rank: 1
等 级:新手上路
帖 子:5
专家分:0
注 册:2014-2-27
结帖率:50%
收藏
已结贴  问题点数:8 回复次数:3 
jsp页面调用js脚本文件如何解决乱码问题
两个文件的写完之后,结果出现乱码,怎么解决,求各位大神帮忙

我的js文件是这样的:
function clock_12h()
 {
  var today = new Date(); //获得当前时间
  //获得年、月、日,Date()函数中的月份是从0-11计算
  var year = today.getFullYear();  
  var month = today.getMonth()+1;
  var date = today.getDate();
  var hour = today.getHours();  //获得小时、分钟、秒
  var minute = today.getMinutes();
  var second = today.getSeconds();
 
  var apm="AM"; //默认显示上午: AM
  if (hour>12) //按12小时制显示
  {
     hour=hour-12;
     apm="PM"  ;
  }
  var weekday = 0;
  switch(today.getDay()){
     case 0:
       weekday = "星期日";
     break;
     case 1:
       weekday = "星期一";
     break;
     case 2:
       weekday = "星期二";
     break;
     case 3:
       weekday = "星期三";
     break;
     case 4:
       weekday = "星期四";
     break;
     case 5:
       weekday = "星期五";
     break;
     case 6:
       weekday = "星期六";
     break;
  }
   /*设置div的内容为当前时间*/
  document.getElementById("myclock").innerHTML="<h2>尊敬的用户您好,欢迎登录博客系统,"+year+"年"+month+"月"+date+"日&nbsp;"+hour+":"+minute+":"+second+"&nbsp;"+apm+"&nbsp;"+weekday+"</h2>";
 }
 /*使用setInterval()每间隔指定毫秒后调用clock_12h()*/
 var myTime = setInterval("clock_12h()",1000);

jsp文件的调用部分这样写:
<head>
    <script type="text/javascript" src="js/index.js"></script>
</head>
<body>
    <table>
        <tr>
            <td id="myclock"></td>
        </tr>
    </table>
</body>
搜索更多相关主题的帖子: function minute second 如何 
2014-03-02 12:38
hhwz
Rank: 13Rank: 13Rank: 13Rank: 13
等 级:贵宾
威 望:87
帖 子:687
专家分:4502
注 册:2011-5-22
收藏
得分:8 
jsp head 加上<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
2014-03-03 10:53
cmjztt
Rank: 1
等 级:新手上路
帖 子:5
专家分:0
注 册:2014-2-27
收藏
得分:0 
不好意思,我试了,但还是乱码,不行,请问还有其他的解决方法吗?
2014-04-02 17:03
cmjztt
Rank: 1
等 级:新手上路
帖 子:5
专家分:0
注 册:2014-2-27
收藏
得分:0 
好吧,我终于解决了这个问题了,还是找了好久之后才找到的,不过依然谢谢
在web.xml文件中加入下面代码
<jsp-config>
         <jsp-property-group>
             <description>
                  Special property group for JSP Configuration JSP example.
             </description>
             <display-name>JSPConfiguration</display-name>
             <url-pattern>*.jsp</url-pattern>
             <el-ignored>true</el-ignored>
             <page-encoding>UTF-8</page-encoding>
             <scripting-invalid>false</scripting-invalid>
             <include-prelude></include-prelude>
             <include-coda></include-coda>
             <description>
                  Special property group for JSP Configuration JSP example.
             </description>
             <display-name>JSPConfiguration</display-name>
             <url-pattern>*.html</url-pattern>
             <el-ignored>true</el-ignored>
             <page-encoding>UTF-8</page-encoding>
             <scripting-invalid>false</scripting-invalid>
             <include-prelude></include-prelude>
             <include-coda></include-coda>
             <description>
                  Special property group for JSP Configuration JSP example.
             </description>
             <display-name>JSPConfiguration</display-name>
             <url-pattern>*.txt</url-pattern>
             <el-ignored>true</el-ignored>
             <page-encoding>UTF-8</page-encoding>
             <scripting-invalid>false</scripting-invalid>
             <include-prelude></include-prelude>
             <include-coda></include-coda>
             <description>
                  Special property group for JSP Configuration JSP example.
             </description>
             <display-name>JSPConfiguration</display-name>
             <url-pattern>*.js</url-pattern>
             <el-ignored>true</el-ignored>
             <page-encoding>UTF-8</page-encoding>
             <scripting-invalid>false</scripting-invalid>
             <include-prelude></include-prelude>
             <include-coda></include-coda>
         </jsp-property-group>
     </jsp-config>
2014-04-02 17:19
快速回复:jsp页面调用js脚本文件如何解决乱码问题
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.032005 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved