百度模糊修改

    xiaoxiao2021-03-25  163

    %@ 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 οnclick='getA(this)'>"+part.getPName()+"</td></tr>"); } out.print("</table>"); out.flush(); out.close(); } catch (Exception e) { // TODO: handle exception e.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 stub return session.createQuery("from TPart a where a.PName like ?").setString(0, '%'+PName+'%').list(); } }); }
    转载请注明原文地址: https://ju.6miu.com/read-7999.html

    最新回复(0)