可能重复:
从 JSP 文件调用 servlet
我使用以下代码conn.java
从index.jsp
. 有用。
<%@page import= "java.util.ArrayList"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<%@ page import= "aa.conn" %>
<jsp:useBean id= "conne" class= "conn" scope= "session"/>
<jsp:setProperty name= "conne" property= "*"/>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JSP</title>
</head>
<body>
<link rel="stylesheet" href="rowcolor.css" type="text/css">
<%
conne.con(request, response);
ArrayList newlist=null;
newlist=(ArrayList)request.getAttribute("data1");
int noofrows=(Integer)newlist.get(0);
int q = noofrows / 5;
if(noofrows%5!=0)
q+=1;
out.println("Pages --->>>");
for (int t = 1; t <= q; t++) {
out.println("<a href=index.jsp?id=" + t + " name=" + t + "id=" + t + ">");
out.println(" " + t);
out.println("</a>");
}
conne.disp(request, response);
conne.dispgraphtab(request, response);
%>
</body>
</html>
但是,下面的代码不起作用。我想从NewServlet
打电话graphcon.jsp
。
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<%@ page import= "aa.NewServlet" %>
<jsp:useBean id= "co" class= "NewServlet" scope= "session"/>
<jsp:setProperty name= "co" property= "*"/>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JSP Page</title>
</head>
<body>
</body>
</html>
这段代码有什么问题?错误是:
exception
javax.servlet.ServletException: java.lang.InstantiationException: NewServlet
root cause
java.lang.InstantiationException: NewServlet