又出错!!!

weiyoufu 2006-12-01 10:50:15
程序的原意是输出带两位小数的百分数
原代码:
<%@ page contentType="text/html; charset=gb2312" language="java" import="java.sql.*,java.util.*,java.math.*;" errorPage="" %>
<html>
<head>
<title>邮箱运营</title>
<style type="text/css">
<!--
body {
background-color: #EEEEEE;
}
.style1 {
font-size: 14px;
font-weight: bold;
}
td {
font-size: 12px;
}
-->
</style></head>
<%! String url,user,password,sql,quhao,rongliang,tel,fangshi,shijian,qingkuang;%>
<%! Connection conn;%>
<%! ResultSet rs;%>
<%! Statement stmt;%>
<%! int hezec,hezecbatint;%>
<%! double hezecbat;%>
<%! FormatPercent(int, int);%>
<body>
<%
try{
Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver").newInstance();
String url="jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=mail";
String user="sa";
String password="123456";
Connection conn= DriverManager.getConnection(url,user,password);
Statement stmt=conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);
sql="select count(*) as hezecbatint from ruyi where quhao='0530' and tel>'13300000000' and fangshi='bat' and shijian like'2006-9%' ";
rs=stmt.executeQuery(sql);
rs.next();
hezecbatint=rs.getInt("hezecbatint");
sql="select count(*) as hezec from ruyi where quhao='0530' and tel>'13300000000' and shijian like'2006-9%' ";
rs=stmt.executeQuery(sql);
rs.next();
hezec=rs.getInt("hezec");
%>
<%=hezecbatint%>.<%=hezec%>.<%=FormatPercent(hezecbatint/hezec,2)%>
<%
rs.close();
stmt.close();
conn.close();
}catch(Exception e){
out.println(e.toString());
}
%>
</body>
</html>

出错提示:
org.apache.jasper.JasperException: Unable to compile class for JSP

An error occurred at line: 25 in the jsp file: /333.jsp
Generated servlet error:
Return type for the method is missing

An error occurred at line: 25 in the jsp file: /333.jsp
Generated servlet error:
Syntax error on token "int", VariableDeclaratorId expected after this token

An error occurred at line: 25 in the jsp file: /333.jsp
Generated servlet error:
Syntax error on token "int", VariableDeclaratorId expected after this token

An error occurred at line: 44 in the jsp file: /333.jsp
Generated servlet error:
The method FormatPercent(int, int) is undefined for the type _333_jsp


org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:510)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:375)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:314)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:264)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
...全文
218 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
szuzsq 2006-12-01
  • 打赏
  • 举报
回复
这样声明方法:
<%!int FormatPercent(int i, int j) {
//return Integer.toString(i + j);
return i + j;
}%>
-------------------------------------------------------------
<%=FormatPercent(2, 3)%>
szuzsq 2006-12-01
  • 打赏
  • 举报
回复
<%FormatPercent(int ,int );%>
定义方法?
--------------------------------------------
注释是这样的
<%//String url%>
<%-- String url--%>
--------------------------------------------
<% String url;%>
<%String url="jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=mail";%>
你这两个地方重复了?

---------------------------------------------
以下通过:
---------------------------------------------------
<%@ page contentType="text/html; charset=gb2312" language="java" import="java.sql.*,java.util.*,java.math.*;" errorPage=""%>
<html>
<head>
<title>邮箱运营</title>
<style type="text/css">
<!--
body {
background-color: #EEEEEE;
}
.style1 {
font-size: 14px;
font-weight: bold;
}
td {
font-size: 12px;
}
-->
</style>
</head>
<%String url, user, password, sql, quhao, rongliang, tel, fangshi, shijian, qingkuang;%>
<%Connection conn;%>
<%ResultSet rs;%>
<%Statement stmt;%>
<%int hezec, hezecbatint;%>
<%double hezecbat;%>
<%//FormatPercent(int ,int );%>
<body>
<%try {
Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver").newInstance();
url = "jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=mail";
user = "sa";
password = "123456";
conn = DriverManager.getConnection(url, user, password);
stmt = conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE);
sql = "select count(*) as hezecbatint from ruyi where quhao='0530' and tel>'13300000000' and fangshi='bat' and shijian like'2006-9%' ";
rs = stmt.executeQuery(sql);
rs.next();
hezecbatint = rs.getInt("hezecbatint");
sql = "select count(*) as hezec from ruyi where quhao='0530' and tel>'13300000000' and shijian like'2006-9%' ";
rs = stmt.executeQuery(sql);
rs.next();
hezec = rs.getInt("hezec");

%>
<%=hezecbatint%>
.
<%=hezec%>
.
<%//=FormatPercent(hezecbatint/hezec,2)%>
<%rs.close();
stmt.close();
conn.close();
}
catch (Exception e) {
out.println(e.toString());
}

%>
</body>
</html>
weiyoufu 2006-12-01
  • 打赏
  • 举报
回复
能不能帮助解决问题啊?在线等..
Sunny319 2006-12-01
  • 打赏
  • 举报
回复
<% String url,user,password,sql,quhao,rongliang,tel,fangshi,shijian,qingkuang;
Connection conn;
ResultSet rs;
Statement stmt;
int hezec,hezecbatint;
double hezecbat;
FormatPercent(int, int);%>
<body>
<%
try{
rg_nightkid 2006-12-01
  • 打赏
  • 举报
回复
<%! String url,user,password,sql,quhao,rongliang,tel,fangshi,shijian,qingkuang;%>
<%! Connection conn;%>
<%! ResultSet rs;%>
<%! Statement stmt;%>
<%! int hezec,hezecbatint;%>
<%! double hezecbat;%>
<%! FormatPercent(int, int);%>

这么做作
galant2008 2006-12-01
  • 打赏
  • 举报
回复
<%! String url,user,password,sql,quhao,rongliang,tel,fangshi,shijian,qingkuang;%>
<%! Connection conn;%>
<%! ResultSet rs;%>
<%! Statement stmt;%>
<%! int hezec,hezecbatint;%>
<%! double hezecbat;%>
<%! FormatPercent(int, int);%>

这里是<%@ %>这样才对吧.

81,092

社区成员

发帖
与我相关
我的任务
社区描述
Java Web 开发
社区管理员
  • Web 开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧