日期:2014-05-16 浏览次数:20705 次
写的比较简单。
jsp 页面:
javascript部分:
addName.value是从别的地方获取到的值。做为参数传递给Action.
$.get('<s:url action="addAlbum" />', { name : addName.value},
function(data){
if(data!=null && data!=""){
folderId=data;
}else{
alert("Add album failed.");
return;
}
});
?struts.xml配置:
<action name="addAlbum" class="com.gti.epd.cmis.action.facility.FacilityAjaxAction" method="addAlbum">
<result name="success">/facility/FacilityAdd.jsp</result>
</action>
?struts.xml配置中的result部分,没什么用。因为Action不会返回success.
Action class配置:
只看action方法:
public String addAlbum() throws Exception {
HttpServletRequest request = ServletActionContext.getRequest();
HttpServletResponse response = ServletActionContext.getResponse();
String albumName = request.getParameter("name");
String responseHMTL = "";
Long folderId = null;
try {
// 保存albumName到Folder,返回FolderId值。
if (albumName != null && albumName.trim().length() > 0) {
FolderBO folderBO = new FolderBO();
folderBO.setFolderName(albumName.trim());
folderBO.setFolderType(FolderVOHelper.FACILITY_PHOTO);
folderId = folderSaveService.save(folderBO);
}
if (albumName != null) {
responseHMTL = responseHMTL + folderId;
} else {
responseHMTL = responseHMTL + "albumName is null.";
}
response.getWriter().print(responseHMTL);
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
?
?
?