在jsp中不能new java对象吗 为什么从我一开始new的地方就出错了
<%@pagelanguage="java"import="java.util.*"pageEncoding="GB2312"%><%Stringpath=request...
<%@ page language="java" import="java.util.*" pageEncoding="GB2312"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
System.out.println("ka;jeiop");
Student stu1=new Student("1","张三","男","01",723.0);
Student stu2=new Student("2","李云","女","02",689.0);
Student stu3=new Student("3","孙婷","女","03",690.0);
List arrlist=new ArrayList();
arrlist.add(stu1);
arrlist.add(stu2);
arrlist.add(stu3);
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">
<title>My JSP 'student.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">
-->
</head>
<body>
<table border=1px>
<tr>
<td>编号</td>
<td>姓名</td>
<td>性别</td>
<td>班级</td>
<td>成绩</td>
</tr>
<% for(int i=0;i<arrlist.size();i++){
Student stu=new Student();
stu=(Student)arrlist.get(i);
%>
<tr>
<td><%=stu.getNum()%></td>
<td><%=stu.getName()%></td>
<td><%=stu.getSex()%></td>
<td><%=stu.getBanji()%></td>
<td><%=stu.getGrade()%> </td>
</tr>
<% } %>
</table>
</body>
</html> 展开
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
System.out.println("ka;jeiop");
Student stu1=new Student("1","张三","男","01",723.0);
Student stu2=new Student("2","李云","女","02",689.0);
Student stu3=new Student("3","孙婷","女","03",690.0);
List arrlist=new ArrayList();
arrlist.add(stu1);
arrlist.add(stu2);
arrlist.add(stu3);
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">
<title>My JSP 'student.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">
-->
</head>
<body>
<table border=1px>
<tr>
<td>编号</td>
<td>姓名</td>
<td>性别</td>
<td>班级</td>
<td>成绩</td>
</tr>
<% for(int i=0;i<arrlist.size();i++){
Student stu=new Student();
stu=(Student)arrlist.get(i);
%>
<tr>
<td><%=stu.getNum()%></td>
<td><%=stu.getName()%></td>
<td><%=stu.getSex()%></td>
<td><%=stu.getBanji()%></td>
<td><%=stu.getGrade()%> </td>
</tr>
<% } %>
</table>
</body>
</html> 展开
9个回答
展开全部
你没有导入包,你可以这样写
<%@ page language="java" import="java.util.*,你Student所在包" pageEncoding="GB2312"%>
或者你这样
<%@ page import="你的student所在包";%>
<%@ page language="java" import="java.util.*,你Student所在包" pageEncoding="GB2312"%>
或者你这样
<%@ page import="你的student所在包";%>
追问
若是在项目的默认包中怎么写啊
追答
你如果用开放工具的话点到那个类上边右键copy Qualified Name拷贝完整路径如我下
/Demo05/src/com/icar/entity/User.java
如果是这样你要去掉com以前的把/变为点去掉.java
本回答被提问者和网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
可以要用的那个类,先放到一个package中,再导包
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
<%@ page import="java.util.*"%>
导入Student对象的包
导入Student对象的包
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
能new但是要在使用时要进行导包
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
可以,import="你要new的类包的路径"
追问
可以了
工程下的默认包里建的Student类,然后是 import="java.util.*,Student"导入的,怎么写才不报错呢
必须新建一个包吗,
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询