package com.admin;
import java.util.ArrayList;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import org.apache.struts2.ServletActionContext;
import com.core.CalTime;
import com.opensymphony.xwork2.Action;
import db.link.ParkinfoDao;
import db.link.Parking_info;
import db.link.Parking_record;
import db.link.ParkreDao;
//import db.link.ParkreDao;
import db.link.Prinfo;
import db.link.User;
import db.link.UserDao;
public class LoginAction implements Action{
private String username;
private String password;
private String type;
private String tip;
private ArrayList<User> list;
public ArrayList<Parking_info> plist;
public ArrayList<String> slist;//这是重点!
public ArrayList<Parking_record> prlist;
public int a[][];//这是重点!
public ArrayList<Double> fare;//这是重点!
//public ArrayList<Prinfo> prlist=new ArrayList<Prinfo>();
private UserDao userdao=new UserDao();
private ParkinfoDao pdao=new ParkinfoDao();
private ParkreDao rdao=new ParkreDao();
public LoginAction(){
}
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
public String getType() {
return type;
}
public void setType(String type) {
this.type = type;
}
public String getTip() {
return tip;
}
public void setTip(String tip) {
this.tip = tip;
}
public String execute(){
list=userdao.getUserList();
plist=pdao.getPrList();
slist=rdao.getCarNum();
/*for(int i=0;i<plist.size();i++){
prlist.add(new Prinfo());
prlist.get(i).setId(plist.get(i).getId());
prlist.get(i).setStatus(plist.get(i).getStatus());
prlist.get(i).setPlicense(plist.get(i).getId());
}*/
prlist=rdao.getPrList();
CalTime clt=new CalTime();
ArrayList<Integer> il=new ArrayList<Integer>();
fare=new ArrayList<Double>();
for(int i=0;i<prlist.size();i++){
Parking_record pr=prlist.get(i);
if(pr.getFare()==0){
fare.add(clt.getNowFare(pr.getIntime()));
}
}
a=new int[fare.size()][3];
int j=0;
for(int i=0;i<prlist.size();i++){
Parking_record pr=prlist.get(i);
if(pr.getDuration()==0){
il=clt.getShowTime(pr.getIntime());
a[j][0]=il.get(0);
a[j][1]=il.get(1);
a[j][2]=il.get(2);
j++;
}
}
User user;
for(int i=0;i<list.size();i++){
user=list.get(i);
if(user.getUsername().equals(username)&&user.getPassword().equals(password)){
if(user.getType().equals(type)){
HttpServletRequest request=ServletActionContext.getRequest();
HttpSession session=request.getSession();
session.setAttribute("username", username);
session.setAttribute("plist", plist);
session.setAttribute("prlist", prlist);
System.out.println(fare.get(0)+":"+slist.get(1));
if(type.equals("operator")){
return SUCCESS;
}
else{
return LOGIN;
}
}
else{
setTip("用户与类型不匹配");
return ERROR;
}
}
}
setUsername("USERNAME");
setPassword("Password");
setTip("用户或密码错误,请重新输入");
return ERROR;
}
}
以上是后台的代码
<div class="content" id="print" style="display:none">
<!--<font size="3">车牌号码:</font> <input type="text"></input> <input
type="submit" value="登记"></input>-->
<input type="text" value="输入关键字">
<s:form>
<table style="width: 60%;margin:auto">
<tr>
<th>编号</th>
<th>车牌号码</th>
<th>所在车位</th>
<th>入场时间</th>
<th>出场时间</th>
<th>停车时长</th>
<th>总费用</th>
</tr>
<s:iterator value="prlist" status="sts" id="prl" begin="0" end="8">
<tr>
<td><s:property value="#prl.id"/></td>
<td><s:property value="#prl.plate_license"/></td>
<td><s:property value="#prl.parking_num"/></td>
<td><s:property value="#prl.intime"/></td>
<td><s:if test="#prl.outtime == null ">未离场</s:if>
<s:else><s:property value="#prl.outtime"/></s:else>
<td><s:if test="#prl.duration == 0">
<s:property value="time[<%=j%>][0]"/>天
<s:property value="time[<%=j%>][1]"/>小时
<s:property value="time[<%=j%>][2]"/>分钟
<% j++; %>
</s:if>
<s:else><s:property value="#prl.duration"/></s:else>
<td><s:property value="fare[0]"/>
<s:else><s:property value="#prl.fare"/></s:else></td>
</tr>
</s:iterator>
</table>
</s:form>
</div>
<div class="content" id="abnormal" style="display:none">
<!--<font size="3">车牌号码:</font> <input type="text"></input> <input
type="submit" value="登记"></input>
<input type="text" value="输入车位号码"> -->
<input type="text" name="word" placeholder="请输入车位号码"/>
<input type="submit" value="Search" /><br/>
<s:form>
<table style="width: 60%;margin:auto">
<tr>
<th>车位号码</th>
<th>车位状态</th>
<th>车牌号码</th>
<th>状态修改</th>
</tr>
<s:iterator value="plist" status="st" id="list" begin="0" end="8">
<tr>
<td><s:property value="#list.id"/></td>
<td><s:if test="#list.status == 'idle' ">空闲</s:if>
<s:elseif test="#list.status == 'assigned' ">已分配</s:elseif>
<s:else>异常</s:else></td>
<td><s:if test="slist[#st.index] == null ">无车辆</s:if>
<s:else><s:property value="slist[#st.index]"/></s:else></td>
<td><a href="http://www.w3school.com.cn/" target="_blank">修改</a></td>
</tr>
</s:iterator>
</table>
</s:form>
</div>
以上是前台的代码
就是很奇怪,数组slist的值可以接收到,并且正常使用。然而数组fare的值却接收不到,页面上对应的fare一栏全是空的。我很疑惑,为什么会这样,有大佬能为我解答吗?