当前位置:首页 > 开发 > Web前端 > 前端 > 正文

Incompatible operand types String and int

发表于: 2011-11-18   作者:cooler1217   来源:转载   浏览:
jsp
摘要: <%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%> <%@ taglib prefix="s" uri="/struts-tags"%> <%@ taglib prefix

<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib prefix="s" uri="/struts-tags"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://"
			+ request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
	<head>
		<base href="<%=basePath%>">

		<title>My JSP 'index.jsp' starting page</title>
		<meta http-equiv="pragma" content="no-cache">
		<meta http-equiv="cache-control" content="no-cache">
		<meta http-equiv="expires" content="0">
		<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
		<meta http-equiv="description" content="This is my page">
		<!--
	<link rel="stylesheet" type="text/css" href="styles.css">
	-->
		<script type="text/javascript">
 	function sum(){
 		var form = document.getElementById("sum");
		alert(form);
		//form.method="POST";
		//form.action="mystruts/sum.action";
 		//form.submit();
 		var ajax = InitAjax();
 		alert(ajax);
 	}
 	
 	function InitAjax()
	{
	 var ajax=false;
	 try {
	  ajax = new ActiveXObject("Msxml2.XMLHTTP");
	 } catch (e) {
	  try {
	   ajax = new ActiveXObject("Microsoft.XMLHTTP");
	  } catch (E) {
	   ajax = false;
	  }
	 }
	 if (!ajax && typeof XMLHttpRequest!='undefined') {
	  ajax = new XMLHttpRequest();
	 }
	 return ajax;
	}
	
	function ajaxGet(){
	//需要进行Ajax的URL地址
	 var url = "";
	 //获取新闻显示层的位置
	 var show = document.getElementByIdx("show_news");
	 //实例化Ajax对象
	 var ajax = InitAjax();
	 //使用Get方式进行请求
	 ajax.open("GET", url, true);
	 //获取执行状态
	 ajax.onreadystatechange = function() {
	  //如果执行是状态正常,那么就把返回的内容赋值给上面指定的层
	  if (ajax.readyState == 4 && ajax.status == 200) {
	   show.innerHTML = ajax.responseText;
	  }
	 }
	 //发送空
	 ajax.send(null);
	}
	
	function ajaxPost(){
	//接收表单的URL地址
	 var url = "/";
	 //需要POST的值,把每个变量都通过&来联接
	 var postStr = "user_name="+ userName +"&user_age="+ userAge +"&user_sex="+ userSex;
	 //实例化Ajax
	 var ajax = InitAjax();
	 
	 //通过Post方式打开连接
	 ajax.open("POST", url, true);
	 //定义传输的文件HTTP头信息
	 ajax.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
	 //发送POST数据
	 ajax.send(postStr);
	 //获取执行状态
	 ajax.onreadystatechange = function() {
	  //如果执行状态成功,那么就把返回信息写到指定的层里
	  if (ajax.readyState == 4 && ajax.status == 200) {
	   msg.innerHTML = ajax.responseText;
	  }
	}
	}
	
 	</script>
	</head>

	<body>
		<jsp:include page="test/head.jsp"></jsp:include>
		<hr/>
		This is my JSP page. 
		<br />
		<!-- 
		<s:form action="mystruts/sum.action">
			<s:textfield name="operand1" label=" 操作数1" />
			<s:textfield name="operand2" label=" 操作数2" />
			<s:submit value="代数和" />
		</s:form>
		 -->
		<br>
		<form action="mystruts/sum.action" id="sum">
			<input type="text" name="operand1" label=" 操作数1" />
			<input type="text" name="operand2" label=" 操作数2" />
			<input type="submit" value="代数和" />
			<input type="button" value="代数和2" onclick="sum()" />
		</form>
		${2*4 }
		<c:if test="${1==1}">dd</c:if>
		<hr/>
		<jsp:include page="test/foot.jsp"></jsp:include>
	</body>
</html>



报错原因:

<c:if test="${1==1}">dd</c:if>


比较内容${1==1}没有任何意义,一般解释为 变量和变量比较,或变量和常量比较,两个常量没意义,所报错,但没有影响

Incompatible operand types String and int

  • 0

    开心

    开心

  • 0

    板砖

    板砖

  • 0

    感动

    感动

  • 0

    有用

    有用

  • 0

    疑问

    疑问

  • 0

    难过

    难过

  • 0

    无聊

    无聊

  • 0

    震惊

    震惊

版权所有 IT知识库 CopyRight © 2009-2015 IT知识库 IT610.com , All Rights Reserved. 京ICP备09083238号