百度模糊修改

前端之家收集整理的这篇文章主要介绍了百度模糊修改前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
 
 
%@ 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;
}
@H_502_115@ }
//点击改行,上去了并消失
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 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://www.f2er.com/ajax/161350.html

猜你在找的Ajax相关文章