manage.jsp
<%@ page language="java" import="java.util.*,org.lee.entity.*"
pageEncoding="UTF-8"%>
<%
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 'manage.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>
<h1>
进入管理页面
</h1>
<form action="search" method="post">
<table>
<tr>
<td>
请输入需要查询人的姓名
</td>
<td>
<input type="text" name="search" />
</td>
<td>
<input type="submit" value="提交" />
</td>
</tr>
</table>
</form>
<table border="1">
<tr>
<td>
序号
</td>
<td>
用户名
</td>
<td>
密码
</td>
<td>
性别
</td>
<td>
年龄
</td>
<td>
地址
</td>
</tr>
<tr> <%
List<Loginentity> list = (List<Loginentity>) request.getSession()
.getAttribute("list"); for (Loginentity loginentity : list) {
%> <td><%=loginentity.lid%></td>
<td><%=loginentity.lname%></td>
<td><%=loginentity.lpassword%></td>
<td><%=loginentity.lsex%></td>
<td><%=loginentity.lage%></td>
<td><%=loginentity.laddress%></td> <%
}
%> </tr>
</table>
</body>
</html>servletpublic class Search extends HttpServlet { /**
* Destruction of the servlet. <br>
*/
public void destroy() {
super.destroy(); // Just puts "destroy" string in log
// Put your code here
} /**
* The doPost method of the servlet. <br>
*
* This method is called when a form has its tag value method equals to
* post.
*
* @param request
* the request send by the client to the server
* @param response
* the response send by the server to the client
* @throws ServletException
* if an error occurred
* @throws IOException
* if an error occurred
*/
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException { response.setContentType("text/html");
String search = request.getParameter("search");
DBconnection dbconnection = new DBconnection();
Connection conn;
try {
conn = dbconnection.getDBconnection();
Statement st = conn.createStatement();
String sql = "select *from login where lname = '" + search + "'";
ResultSet rs = st.executeQuery(sql);
List list = new ArrayList();
HttpSession session = request.getSession();
if (rs.next()) {
Loginentity loginentity = new Loginentity(){};
loginentity.setLid(rs.getInt("lid"));
loginentity.setLname(rs.getString("lname"));
loginentity.setLpassword(rs.getString("lpassword"));
loginentity.setLsex(rs.getString("lsex"));
loginentity.setLage(rs.getInt("lage"));
loginentity.setLaddress(rs.getString("laddress"));
list.add(loginentity);
request.setAttribute("list",list);
getServletContext().getRequestDispatcher("/manage.jsp")
.forward(request, response);
} else {
}
} catch (InstantiationException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IllegalAccessException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
} /**
* Initialization of the servlet. <br>
*
* @throws ServletException
* if an error occurs
*/
public void init() throws ServletException {
// Put your code here
}
}
结果每次打开页面的时候,总报错
HTTP Status 500 - --------------------------------------------------------------------------------type Exception reportmessage description The server encountered an internal error () that prevented it from fulfilling this request.exception org.apache.jasper.JasperException: Unable to compile class for JSP: An error occurred at line: 81 in the jsp file: /manage.jsp
The field Loginentity.lid is not visible
78: for (Loginentity loginentity : list) {
79: %>
80:
81: <td><%=loginentity.lid%></td>
82: <td><%=loginentity.lname%></td>
83: <td><%=loginentity.lpassword%></td>
84: <td><%=loginentity.lsex%></td>控制台显示:
2010-5-22 0:47:02 org.apache.catalina.core.StandardWrapperValve invoke
严重: Servlet.service() for servlet jsp threw exception
org.apache.jasper.JasperException: Unable to compile class for JSP: An error occurred at line: 81 in the jsp file: /manage.jsp
The field Loginentity.lid is not visible
78: for (Loginentity loginentity : list) {
79: %>
80:
81: <td><%=loginentity.lid%></td>
82: <td><%=loginentity.lname%></td>
83: <td><%=loginentity.lpassword%></td>
84: <td><%=loginentity.lsex%></td>
<%@ page language="java" import="java.util.*,org.lee.entity.*"
pageEncoding="UTF-8"%>
<%
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 'manage.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>
<h1>
进入管理页面
</h1>
<form action="search" method="post">
<table>
<tr>
<td>
请输入需要查询人的姓名
</td>
<td>
<input type="text" name="search" />
</td>
<td>
<input type="submit" value="提交" />
</td>
</tr>
</table>
</form>
<table border="1">
<tr>
<td>
序号
</td>
<td>
用户名
</td>
<td>
密码
</td>
<td>
性别
</td>
<td>
年龄
</td>
<td>
地址
</td>
</tr>
<tr> <%
List<Loginentity> list = (List<Loginentity>) request.getSession()
.getAttribute("list"); for (Loginentity loginentity : list) {
%> <td><%=loginentity.lid%></td>
<td><%=loginentity.lname%></td>
<td><%=loginentity.lpassword%></td>
<td><%=loginentity.lsex%></td>
<td><%=loginentity.lage%></td>
<td><%=loginentity.laddress%></td> <%
}
%> </tr>
</table>
</body>
</html>servletpublic class Search extends HttpServlet { /**
* Destruction of the servlet. <br>
*/
public void destroy() {
super.destroy(); // Just puts "destroy" string in log
// Put your code here
} /**
* The doPost method of the servlet. <br>
*
* This method is called when a form has its tag value method equals to
* post.
*
* @param request
* the request send by the client to the server
* @param response
* the response send by the server to the client
* @throws ServletException
* if an error occurred
* @throws IOException
* if an error occurred
*/
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException { response.setContentType("text/html");
String search = request.getParameter("search");
DBconnection dbconnection = new DBconnection();
Connection conn;
try {
conn = dbconnection.getDBconnection();
Statement st = conn.createStatement();
String sql = "select *from login where lname = '" + search + "'";
ResultSet rs = st.executeQuery(sql);
List list = new ArrayList();
HttpSession session = request.getSession();
if (rs.next()) {
Loginentity loginentity = new Loginentity(){};
loginentity.setLid(rs.getInt("lid"));
loginentity.setLname(rs.getString("lname"));
loginentity.setLpassword(rs.getString("lpassword"));
loginentity.setLsex(rs.getString("lsex"));
loginentity.setLage(rs.getInt("lage"));
loginentity.setLaddress(rs.getString("laddress"));
list.add(loginentity);
request.setAttribute("list",list);
getServletContext().getRequestDispatcher("/manage.jsp")
.forward(request, response);
} else {
}
} catch (InstantiationException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IllegalAccessException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
} /**
* Initialization of the servlet. <br>
*
* @throws ServletException
* if an error occurs
*/
public void init() throws ServletException {
// Put your code here
}
}
结果每次打开页面的时候,总报错
HTTP Status 500 - --------------------------------------------------------------------------------type Exception reportmessage description The server encountered an internal error () that prevented it from fulfilling this request.exception org.apache.jasper.JasperException: Unable to compile class for JSP: An error occurred at line: 81 in the jsp file: /manage.jsp
The field Loginentity.lid is not visible
78: for (Loginentity loginentity : list) {
79: %>
80:
81: <td><%=loginentity.lid%></td>
82: <td><%=loginentity.lname%></td>
83: <td><%=loginentity.lpassword%></td>
84: <td><%=loginentity.lsex%></td>控制台显示:
2010-5-22 0:47:02 org.apache.catalina.core.StandardWrapperValve invoke
严重: Servlet.service() for servlet jsp threw exception
org.apache.jasper.JasperException: Unable to compile class for JSP: An error occurred at line: 81 in the jsp file: /manage.jsp
The field Loginentity.lid is not visible
78: for (Loginentity loginentity : list) {
79: %>
80:
81: <td><%=loginentity.lid%></td>
82: <td><%=loginentity.lname%></td>
83: <td><%=loginentity.lpassword%></td>
84: <td><%=loginentity.lsex%></td>
解决方案 »
- 沧海横流方显英雄本色,浮云时代一去不复返了 百万商业圈云平台免费发布,几十万台电脑变成一台不是梦
- 两tomcat上都有一个项目,不知道能不能去得到对方的session
- 准备用Struts2做点东西,想问一下一般项目是用标签还是jstl?
- 大虾们来看看-Tomcat 预载入配置
- 请问怎样把中文变为%XX的形式?
- 文章中过滤HTML标签的问题,欢迎讨论
- JavaBean问题请教!
- 某类有个参数,每次调用这个类,此参数都会自动加一能否实现
- 怎么知道用户是第一次打开网页?类似ASP.NET的if not ispostback then??
- 使用ajax验证用户名是否存在 如何阻止用户提交表单
- 困惑:1970年01月01日 00:00
- 我的jsp页面跳转有问题,大家帮我参详一下。
这两个名字别搞一样、、、
2.Loginentity 类是否一个JavaBean ,纯包含set和get方法
这两个名字不能取一样的,
<form action="search" method="post">
应该写成<form action="/search.do?thisAction=xxx" method="post">
HttpSession session = request.getSession();
if (rs.next()) {
Loginentity loginentity = new Loginentity(){};
loginentity.setLid(rs.getInt("lid"));
loginentity.setLname(rs.getString("lname"));
loginentity.setLpassword(rs.getString("lpassword"));
loginentity.setLsex(rs.getString("lsex"));
loginentity.setLage(rs.getInt("lage"));
loginentity.setLaddress(rs.getString("laddress"));
list.add(loginentity);
request.setAttribute("list",list);
getServletContext().getRequestDispatcher("/manage.jsp")
.forward(request, response);
}]
我不明白,你生成Loginentity loginentity = new Loginentity(){}; 后面会什么加上‘{}’ ,这有什么用呢。没见过这样的写法。
还有你没有外围的 循环,你的list 的size是1 or 0。
还有你在jsp中 获取值的是用 request.getSession("list");而你在servlet中返回这些值 的是使用request.setAttribute("list",list);你之前已经定义了session 为什么不用它来设定呢?
怎样怎么能获取数据啊 。