1、页面table表格制作(含样式)
2、页面 form制作
<form id="userlistform" method="post" action="userlist_login.action">
</form>
3.form内的查询按钮
<input type="submit" id="bt1" value="查询" />
4、根据form的action 创建java类 类名:loginAction 方法名:userlist
创建list public List<UserInfo> user_list = null;
加入 set/get方法
写入类
public String userlist() {
try{
System.out.println("已进入userlist方法");
Map<String, String> map = new HashMap<String, String>();
user_list = bs.queryForList("userlist", map);
setSuccessPath("userlist.jsp");
System.out.print("已进入userlist方法2");
return "success";
}catch(Exception e){
System.out.print(e.toString());
}return "success";
}
5、在login.xml内写入sql查询语句
<select id="userlist" parameterClass="java.util.Map"
resultClass="Model.UserInfo">
SELECT userid,loginname,username,password
FROM userinfo
</select>
6、jsp文件中加入表头引用
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme() + "://"
+ request.getServerName() + ":" + request.getServerPort()
+ path + "/";
%>
<%@taglib uri="/struts-tags" prefix="s"%>
7、在需要展示查询结果列中写入:
iterator相当于jsp文件中的user_list数组
<s:iterator value="#request.user_list" id="fe">
<tr>
<td>
${fe.userid}
</td>
<td>
${fe.username}
</td>
<td>
${fe.loginname}
</td>
<td>
${fe.password}
</td>
</tr>
</s:iterator>
如果有异常抛出 查web.xml
添加jsp拦截器:
<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>*.jsp</url-pattern>
</filter-mapping>
网友评论