日期:2014-05-17 浏览次数:20781 次
package com.ktv.action; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; import SongServiceImpl.SongServiceImpl; import com.ktv.common.action.KtvAction; import com.ktv.entity.Song; import com.ktv.service.SongService; public class SongAction extends KtvAction { private SongService songservice; private List<Song> songs = new ArrayList<Song>(); public SongAction(){ songservice = new SongServiceImpl(); } public String songList(){ String songname = super.getParameter("songname"); songs = songservice.getSongsBySingeralias(songname); System.out.println(songname); System.out.println(songs.get(0).getName()); return "songlist"; } //getter and setter public List<Song> getSongs() { return songs; } public void setSongs(List<Song> songs) { this.songs = songs; } }
$(function(){ $("#btn1").click(function(){ var songname = $("#songnameform").val(); var data = {"songname":songname} var url = "/ktv/song/song!songList.action"; $.post(url,data,function(json){ var songlist = json.songs; alert(songlist); },"json"); }); });
<?xml version="1.0" encoding="UTF-8" ?> <!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.1//EN" "http://struts.apache.org/dtds/struts-2.1.dtd"> <struts> <package name="song" namespace="/song" extends="json-default"> <action name="song" class="com.ktv.action.SongAction"> <result name="songlist" type="json"/> </action> </package> </struts>
public String songList(){ String songname = super.getParameter("songname"); songs = songservice.getSongsBySingeralias(songname); System.out.println(songname); System.out.println(songs.get(0).getName()); return "songlist"; }