action方法:地址栏中传递参数
private JSONArray json ;
/**
* 根据人员名称查询车位信息
* @return
* @throws IOException
* @throws UnsupportedEncodingException
*/
public void selectParkingLotByName() throws SQLException, IOException{
HttpServletResponse response=ServletActionContext.getResponse();
//以下代码从JSON.java中拷过来的
response.setContentType("text/html");
response.setCharacterEncoding("UTF-8");
PrintWriter out;
out = response.getWriter();
String personnelNumber = personnelDAO.selectNumberByID(personnel.getId());
String parkGroup = schedulingDAO.selectParkGroupByPerson(personnelNumber);
parkingLotList = parkingLotDAO.selectParkingLotByGroup(parkGroup);
if(parkingLotList.size()>0 || parkingLotList!=null){
json =new JSONArray();
for(int i=0;i<parkingLotList.size();i++){
JSONObject object=new JSONObject();
object.put("id", parkingLotList.get(i).getId());
object.put("parkingNumber", parkingLotList.get(i).getParkingNumber());
object.put("parkingName", parkingLotList.get(i).getParkingName());
object.put("position", parkingLotList.get(i).getPosition());
object.put("parkGroup", parkingLotList.get(i).getParkGroup());
json.add(object);
}
}
out.println(json.toString());
out.flush();
out.close();
}
struts.xml
<?xml version="1.0" encoding="GBK"?>
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
"http://struts.apache.org/dtds/struts-2.0.dtd">
<struts>
<package name="PDAService" extends="struts-default" namespace="/PDAService">
<action name="service_*" class="cn.com.wewell.PDAService.PDAServiceAction" method="{1}">
</action>
</package>
</struts>