<mce:script type="text/javascript" src="scripts/jquery.js" mce_src="scripts/jquery.js"></mce:script> <mce:script type="text/javascript" src="scripts/json.js" mce_src="scripts/json.js"></mce:script> <script type="text/javascript"> $(document).ready(function(){ $("#father").change(function(){ var id=$(this).val(); //alert(id); $.post("ajaxNamefactory.jspx",{id:id},function(result){ alert(result); $("#name").attr("value",result); }); }); }); ........................................... <select class="inputborder" id="father"> <option value="0">- 请选择加工单位</option> <c:forEach items="${facList}" var="fac"> <option value="${fac.id }">${fac.factoryName }</option> </c:forEach> </select> </td> <td id="input" width="9%" height="53" align="right">收货人:</td> <td colspan="2" align="left"> <input type="text" id="name" style="width:164px; float:left" class="inputborder"/> </td> <td width="17%">发帮日期: 2010年08月31日</td> FactoryAction.java package com.kaisheng.web; import java.io.PrintWriter; import java.util.List; import javax.annotation.Resource; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import net.sf.json.JSONObject; import org.apache.struts2.ServletActionContext; import org.springframework.stereotype.Controller; import com.kaisheng.pojo.Factory; import com.kaisheng.service.FactoryService; import com.opensymphony.xwork2.ActionContext; @Controller public class FactoryAction extends BaseAction<Factory> { private static final long serialVersionUID = -3111924411986332174L; private int id; private Factory factory; private List<Factory> facList; @Resource private FactoryService factoryService; public String ajaxName()throws Exception{ HttpServletRequest request=(HttpServletRequest) ActionContext.getContext().get(ServletActionContext.HTTP_REQUEST); request.setCharacterEncoding("utf-8"); HttpServletResponse response=(HttpServletResponse) ActionContext.getContext().get(ServletActionContext.HTTP_RESPONSE); response.setCharacterEncoding("utf-8"); PrintWriter out=response.getWriter(); factory=factoryService.findById(id); if(factory!=null){ out.print(factory.getReceiveName()); }else{ out.print("error"); } out.flush(); out.close(); return null; } @Override public String del() throws Exception { return null; } @Override public Factory getModel() { return factory; } @Override public String input() throws Exception { return null; } @Override public String list() throws Exception { return null; } @Override public void prepareModel() throws Exception { if(id!=0){ factory=factoryService.findById(id); }else{ factory=new Factory(); } } @Override public String save() throws Exception { return null; } //------------------------get and set method---------------------- public int getId() { return id; } public void setId(int id) { this.id = id; } public Factory getFactory() { return factory; } public void setFactory(Factory factory) { this.factory = factory; } public List<Factory> getFacList() { return facList; } public void setFacList(List<Factory> facList) { this.facList = facList; } } 截图如下: