程序的原意是输出带两位小数的百分数
原代码:
<%@ 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 JSPAn error occurred at line: 25 in the jsp file: /333.jsp
Generated servlet error:
Return type for the method is missingAn error occurred at line: 25 in the jsp file: /333.jsp
Generated servlet error:
Syntax error on token "int", VariableDeclaratorId expected after this tokenAn error occurred at line: 25 in the jsp file: /333.jsp
Generated servlet error:
Syntax error on token "int", VariableDeclaratorId expected after this tokenAn 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)
原代码:
<%@ 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 JSPAn error occurred at line: 25 in the jsp file: /333.jsp
Generated servlet error:
Return type for the method is missingAn error occurred at line: 25 in the jsp file: /333.jsp
Generated servlet error:
Syntax error on token "int", VariableDeclaratorId expected after this tokenAn error occurred at line: 25 in the jsp file: /333.jsp
Generated servlet error:
Syntax error on token "int", VariableDeclaratorId expected after this tokenAn 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)
解决方案 »
- dtree.js 如何增加右键点击事件? 弹出增删改操作,并获取所点击节点的ID
- 关于JS数组集合的一个问题,欢迎高手讨论
- 关于浏览器的状态栏~~
- struts问题:从文档批量导入数据!
- 哪种方法好???文档(gif,txt,doc,zip,rar等)是存储在硬盘还是数据库中?文档下载是用jspsmart还是用ServletOutputStream?
- 我用jsp+javabeans还是asp.net+c#来做的好??
- Java Web登录页面验证问题!!!菜鸟求教!!!
- HELP!改数据时,检测是否有重复数据。
- 结果集问题?急急急
- 一个很奇怪的问题,我的界面为什么会全部偏向右边,不是向右对齐,而是挤在一起。扁扁的,设什么对齐都没有用。
- 欢迎石家庄的java朋友加入改群 33600835 互相学习。。。
- 用eclipse applet嵌入网页的问题,在线等,大哥帮忙啊
<%! Connection conn;%>
<%! ResultSet rs;%>
<%! Statement stmt;%>
<%! int hezec,hezecbatint;%>
<%! double hezecbat;%>
<%! FormatPercent(int, int);%>这里是<%@ %>这样才对吧.
<%! Connection conn;%>
<%! ResultSet rs;%>
<%! Statement stmt;%>
<%! int hezec,hezecbatint;%>
<%! double hezecbat;%>
<%! FormatPercent(int, int);%>这么做作
Connection conn;
ResultSet rs;
Statement stmt;
int hezec,hezecbatint;
double hezecbat;
FormatPercent(int, int);%>
<body>
<%
try{
定义方法?
--------------------------------------------
注释是这样的
<%//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>
<%!int FormatPercent(int i, int j) {
//return Integer.toString(i + j);
return i + j;
}%>
-------------------------------------------------------------
<%=FormatPercent(2, 3)%>