站内搜索: 请输入搜索关键词

当前页面: 开发资料首页J2EE 专题javascript 文件从Jboss移植到websphere时出现的错误!!

javascript 文件从Jboss移植到websphere时出现的错误!!

摘要: javascript 文件从Jboss移植到websphere时出现的错误!!


今天遇到一个很奇怪的问题,在jsp页面中调用一个js文件,在jboss环境下,没有错误,但是在websphere环境下,只要一进入页面,也就是页面一load,就会在页面左下角提示一个js错误。举例如下:
jsp页面中使用(主要内容):

<script language="JavaScript" src="../../js/CmisDict.js" ></script>
<script language="JavaScript">
var hyDict = new CMisDict();
</script>
hyDict.showHtmSelect("","null","SelGbHy");

然后CmisDict.js文件内容如下:

/***************************class CmisDictItem************************************/
function CmisDictItem(strCode,strDes,objGroup){
if(typeof(strCode)!="undefined")
this.code = strCode;
if(typeof(strDes)!="undefined")
this.descript = strDes;
if(typeof(strGroup)!="undefined")
this.group = objGroup;
}

CmisDictItem.prototype.init = function(strCode,strDes,objGroup){
if(typeof(strCode)!="undefined")
this.code = strCode;
if(typeof(strDes)!="undefined")
this.descript = strDes;
if(typeof(strGroup)!="undefined")
this.group = objGroup;
}

CmisDictItem.prototype.getCode = function (){
return this.code;
}

CmisDictItem.prototype.getDescript = function(){
return this.descript;
}

CmisDictItem.prototype.setCode = function(strcode){
this.code = strcode;
}

CmisDictItem.prototype.setDescript = function(strDes){
this.descript = strDes;
}


/***************************class CMisDict************************************/
//
//
//
/*****************************************************************************/
function CMisDict(){
this.arryDicts = new Array();
}

CMisDict.prototype.getDictItem=function(iIndex){
if(iIndex>this.arryDicts.length){
return arryDicts[iIndex];
}
return null;
}

CMisDict.prototype.length = function(){
return this.arryDicts.length;
}

CMisDict.prototype.getPos = function(strCode){
for(var i=0;i<this.arryDicts.length;i++){
return i;
}
}
return -1;
}

CMisDict.prototype.getDescript = function(strCode){

var ipos =this.getPos(strCode);
if(ipos!=-1){
return this.arryDicts[ipos].getDescript();
}else{
return strCode;
}
}


CMisDict.prototype.insert = function(codeDes,codestr){
var temcode,temobj;

if(typeof(codeDes)=="object"){
if(codeDes.constructor=="CmisDictItem"){
temcode = codeDes.getCode();
temobj = codeDes;
}
}else if(typeof(codeDes)=="string" && typeof(codestr)=="string") {
temcode = codeDes;
temobj = new CmisDictItem(codeDes,codestr);
}else{
return this.arryDicts.length;
}

var ipos =this.getPos(temcode);

if(ipos!=-1){
return this.arryDicts.length;
}else{
return this.arryDicts.push(temobj);
}

}

CMisDict.prototype.remove = function(codeDes){

var temcode;

if(typeof(codeDes)=="object")
temcode = codeDes.getCode();
else if(typeof(codeDes)=="string") temcode = codeDes;
else return this.arryDicts.length;

var ipos =this.getPos(temcode);

if(ipos== 0) {
arryDicts.shift();
}else if(ipos>0){
for(var k=ipos;k<this.arryDicts.length-1;k++){
}
this.arryDicts.length = this.arryDicts.length-1;
}

return this.arryDicts.length;
}

/**
//istyle:默认为select
**/
CMisDict.prototype.getSingleSelHtm = function(strSelectCode,strname,istyle,strid,strclass){
var style;
var strhtml="";
var str1="";
var str2="";
if(typeof(istyle)=="undefined"){
style=0;
}else{
style=istyle;
}
if(style==1){
str1 ='<input type="hidden" ';
str1 = 'id ="'+ strid +'" ';
}

if(typeof(strname)!="undefined"){
str1 = str1 + ' name ="'+ strname +'" ';
}

str1 = str1 + ' value ="'+ strSelectCode +'">';
str1 = str1 + this.getDescript(strSelectCode);
strhtml = str1;
}else{
str1="<select ";
str1 = ' id ="'+ strid +'" ';
}
if(typeof(strname)!="undefined"){
str1 = str1 + ' name ="'+ strname +'" ';
}

if(typeof(strclass)!="undefined"){
str1 = str1 + ' class ="'+ strclass +'" ';
}
str1 = str1 +">";
strhtml = str1;

str2 = '<option value="' + strSelectCode +'">';
str2 = str2 + this.getDescript(strSelectCode) +'</option>';
strhtml = str1 + str2 +'</select>';
}
return strhtml;
}

/*******************************************************************/
//strname 必要:select标签的name属性
//strSelectCode可选:选中的代码名称
//strid 可选:select标签的id属性
//strclass 可选:select标签的class属性
//isize 可选:select标签的size属性
/*******************************************************************/
CMisDict.prototype.getHtmSelect = function(strname,strSelectCode,strid,strclass,isize){

var htmSelect="";
var strSelect = '<select ';
var objdicItem;

if(typeof(strid)!="undefined") {
if(strid!="")
strSelect=strSelect +' id="' + strid +'" ';
}
strSelect=strSelect +' name="' + strname +'" ';
if(typeof(isize)!="undefined") strSelect = strSelect +' size="' + isize +'" ';
if(typeof(strclass)!="undefined") strSelect = strSelect +' class="' + strclass +'" ';
strSelect = strSelect + '>';

htmSelect = strSelect;
//write opt
for(var i=0;i<this.arryDicts.length;i++){
stropt = '<option value="' + objdicItem.getCode() +'" ';
if(strSelectCode==objdicItem.getCode()){
stropt=stropt + ' selected '
}
}
stropt=stropt+">"
htmSelect = htmSelect +" " +stropt;

htmSelect = htmSelect + objdicItem.getDescript();
htmSelect = htmSelect + "</option>";
}
htmSelect = htmSelect + "</select>"
return htmSelect;
}

/*******************************************************************/
//strname 必要:select标签的name属性
//strSelectCode可选:选中的代码名称
//strid 可选:select标签的id属性
//strclass 可选:select标签的class属性
//isize 可选:select标签的size属性
/*******************************************************************/
CMisDict.prototype.showHtmSelect = function(strname,strSelectCode,strid,strclass,isize){

document.write(this.getHtmSelect(strname,strSelectCode,strid,strclass,isize))

}
/*******************************************************************/
//strSelectCode可选:选中的代码名称
//strname 可选:select标签的name属性
//istyle 可选:默认为select,为1时生成一个隐藏域及显示的名称
//strid 可选:select标签的id属性
//strclass 可选:select标签的class属性
/*******************************************************************/
CMisDict.prototype.showSingle = function(strSelectCode,strname,istyle,strid,strclass){

document.write(this.getSingleSelHtm(strSelectCode,strname,istyle,strid,strclass));

}

说明:这是一个构成下拉菜单的js文件,如果把这个js的引用删掉就没有问题了。
最后访问文件时:报出错误:
行:11
字符:1
代码:0
错误:语法错误

这样的一个jsp在jboss下运行没有问题,但是在websphere下就会报出这个错误,即使在jsp开头引用这个js文件,但在下面的内容中没有使用他里面的方法,也会报这个错误,真的不知道错在哪里,恳请大家指点一下,谢谢了




这应该是JBOSS与websphere在对JS的解释上有所差异造成的.
而且可能是TYPEOF.
查查相关的说明手册看看吧.


to 楼主:

我用的是websphere,按照楼主类似的方法调用一个JS包,
发现报错,因为我以前也调用过JS包,对比一下发现有一处与楼主的不同:
<script language="JavaScript" src="../../js/CmisDict.js" ></script>
这句改成:
<script type="text/javascript" src="../../js/CmisDict.js"></script>
试试!





PS:
<script type="text/javascript" src="../../js/CmisDict.js"></script>中CmisDict.js的路径楼主要确保正确!


↑返回目录
前一篇: 怎么用 struts的令牌机制解决二次提交的问题
后一篇: spring 和 struts整合的问题: