%@ page language="java" import="java.util.*" pageEncoding="utf-8"%><%@taglib prefix="s" uri="/struts-tags"%><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">**-----------------JS页面----------------------**var xmlhttp;function getIE(){if(window.XMLHttpRequest){xmlhttp=new XMLHttpRequest();}else{xmlhttp=new ActiveObject("Microsoft.XMLHTTP");}}//动作function getqiwu(obj){getIE();var t=obj.value;if(t.length>0){var url="${pageContext.request.contextpath}/part_all.action?Pname="+t;var myurl=encodeURI(url);xmlhttp.open("post",myurl,true);xmlhttp.send();xmlhttp.onreadystatechange=getBack;}else{document.getElementById("x").innerHTML="";}}function getBack(){if(xmlhttp.readyState==4&&xmlhttp.status==200){document.getElementById("x").innerHTML=xmlhttp.responseText;}}//点击改行,上去了并消失function getA(obj){document.getElementById("name").value=obj.innerHTML;document.getElementById("x").innerHTML="";}**------------------Action--------------------**package com.qw.action;import java.io.PrintWriter;import java.util.List;import javax.servlet.http.HttpServletResponse;import javax.sound.midi.MidiDevice.Info;import org.apache.struts2.ServletActionContext;import com.qw.entity.TPart;import com.qw.service.PartService;public class PartAction {private PartService service=null;private String PName;public PartService getService() {return service;}public void setService(PartService service) {this.service = service;}public String getPname() {return PName;}public void setPname(String pname) {PName = pname;}public String all(){try {String xPName=new String(PName.getBytes("ISO8859_1"),"utf-8");System.out.println(PName+"--------------");List ar=this.service.getAllLike(xPName);HttpServletResponse response=ServletActionContext.getResponse();response.setContentType("text/html;charset=UTF-8");PrintWriter out=response.getWriter();out.print("<table>");for (int i = 0; i < ar.size(); i++) {System.out.println(ar.size()+"asasasasa");TPart part=(TPart) ar.get(i);out.print("<tr><td onclick='getA(this)'>"+part.getPName()+"</td></tr>");}out.print("</table>");out.flush();out.close();} catch (Exception e) {// Todo: handle exceptione.printstacktrace();}return null;}}-----------------DAO------------------------//模糊部门查询public List getLike(final String PName){return this.getHibernateTemplate().executeFind(new HibernateCallback() {public Object doInHibernate(Session session)throws HibernateException,sqlException {// Todo Auto-generated method stubreturn session.createquery("from TPart a where a.PName like ?").setString(0,'%'+PName+'%').list();}});}
原文地址:https://www.jb51.cc/ajax/161350.html
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。