ajax信息提交文档格式.docx

上传人:b****5 文档编号:21645324 上传时间:2023-01-31 格式:DOCX 页数:27 大小:22.44KB
下载 相关 举报
ajax信息提交文档格式.docx_第1页
第1页 / 共27页
ajax信息提交文档格式.docx_第2页
第2页 / 共27页
ajax信息提交文档格式.docx_第3页
第3页 / 共27页
ajax信息提交文档格式.docx_第4页
第4页 / 共27页
ajax信息提交文档格式.docx_第5页
第5页 / 共27页
点击查看更多>>
下载资源
资源描述

ajax信息提交文档格式.docx

《ajax信息提交文档格式.docx》由会员分享,可在线阅读,更多相关《ajax信息提交文档格式.docx(27页珍藏版)》请在冰豆网上搜索。

ajax信息提交文档格式.docx

err为key

//if(errMsg!

='

'

){

//alert(errMsg);

//}

varxmlHttp;

vari=1;

vartype;

functioninitlx(){

setInterval(AjaxSubmit,3000);

}

//ajax提交信息

functionAjaxSubmit(){

varCONSULT_TITLE=document.getElementById("

CONSULT_TITLE"

).value;

if(CONSULT_TITLE.length>

=5&

&

i<

=1){

startRequest(CONSULT_TITLE);

i++;

}

functioncreateXMLHttpRequest(){

if(window.ActiveXObject){

xmlHttp=newActiveXObject("

Microsoft.XMLHTTP"

);

}elseif(window.XMLHttpRequest){

xmlHttp=newXMLHttpRequest();

}

functionstartRequest(searchKeyWord){

createXMLHttpRequest();

xmlHttp.onreadystatechange=handleStateChange;

xmlHttp.open("

POST"

"

/GetAndPostExampleServlet?

searchKeyWord="

+encodeURIComponent(encodeURI(searchKeyWord))+"

"

true);

xmlHttp.send(null);

functionhandleStateChange(){

if(xmlHttp.readyState==4){

if(xmlHttp.status==200){

resbonseText=xmlHttp.responseText;

if(resbonseText.length>

0){

varjsonObj=eval('

('

+resbonseText+'

)'

varhtml="

varlist=jsonObj.list;

for(vari=0;

list!

=null&

list.length;

i++){

varo=list[i];

if(i==0){

html+='

div>

span>

根据'

+o.searchKeyWord+'

查找的类似结果有:

/span>

/div>

}

vartitle=o.title.substring(0,30);

html+='

+'

ahref="

+o.url+'

?

id='

+o.id+'

title="

+o.title+'

style="

color:

#DA70D6;

+title+'

/a>

}

if(html.length>

document.getElementById("

searchDIV"

).style.display="

block"

).innerHTML=html;

}

}else{

alert("

信息失败"

}

}

/script>

/head>

bodyonload="

initlx();

formaction="

../../do?

action=addFrontZmhd"

method="

post"

name="

sdocmsForm"

id="

tablecellspacing="

0"

cellpadding="

width="

100%"

tr>

tdheight="

22"

class="

wyzx_xx_head"

nowrap="

nowrap"

咨询标题:

/td>

colspan="

3"

inputname="

type="

text"

wyzx_xx_input"

size="

75"

>

spanclass="

test_must"

*<

divid="

border:

1pxsolid#EEE685;

display:

none;

/tr>

/table>

/form>

/body>

/html>

2、servlet类

packagemand;

importjava.io.IOException;

importjava.io.PrintWriter;

importjava.util.ArrayList;

importjava.util.List;

importjavax.servlet.ServletException;

importjavax.servlet.http.HttpServlet;

importjavax.servlet.http.HttpServletRequest;

importjavax.servlet.http.HttpServletResponse;

importnet.sf.json.JSONObject;

publicclassGetAndPostExampleServletextendsHttpServlet{

/**

*Constructoroftheobject.

*/

publicGetAndPostExampleServlet(){

super();

*ThedoGetmethodoftheservlet.<

br>

*

*Thismethodiscalledwhenaformhasitstagvaluemethodequalstoget.

*

*@paramrequesttherequestsendbytheclienttotheserver

*@paramresponsetheresponsesendbytheservertotheclient

*@throwsServletExceptionifanerroroccurred

*@throwsIOExceptionifanerroroccurred

publicvoiddoGet(HttpServletRequestrequest,HttpServletResponseresponse)

throwsServletException,IOException{

response.setContentType("

text/html"

PrintWriterout=response.getWriter();

out

.println("

DOCTYPEHTMLPUBLIC\"

-//W3C//DTDHTML4.01Transitional//EN\"

out.println("

HTML>

HEAD>

TITLE>

AServlet<

/TITLE>

/HEAD>

BODY>

out.print("

Thisis"

out.print(this.getClass());

usingtheGETmethod"

/BODY>

/HTML>

out.flush();

out.close();

*ThedoPostmethodoftheservlet.<

*Thismethodiscalledwhenaformhasitstagvaluemethodequalstopost.

publicvoiddoPost(HttpServletRequestrequest,HttpServletResponseresponse)

text/xml"

response.setCharacterEncoding("

StringsearchKeyWord2=request.getParameter("

searchKeyWord"

StringsearchKeyWord=.URLDecoder.decode(searchKeyWord2,"

utf-8"

JSONObjectret=newJSONObject();

List<

JSONObject>

list=newArrayList<

();

JSONObjectjsonComment=newJSONObject();

jsonComment.put("

title"

"

年月日救助老年人100人,不住退役军官300人..."

url"

ShowArticle.jsp"

id"

001002"

searchKeyWord);

System.out.println("

评论列表=========================================="

+jsonComment.toString());

list.add(jsonComment);

ret.put("

list"

list);

Stringasd=request.getParameter("

asd"

PrintWriterout=response.getWriter();

out.print(ret.toString());

}

3、web配置文件(其中里面字体放大、颜色有改变的是ajax信息提交需要的部分)

xmlversion="

1.0"

encoding="

web-appxmlns="

xmlns:

xsi="

http:

//www.w3.org/2001/XMLSchema-instance"

xsi:

schemaLocation="

version="

2.4"

--sinosoftbegin-->

--DefinethedefaultCSSTheme-->

context-param>

param-name>

csstheme<

/param-name>

param-value>

cmsstyle<

/param-value>

/context-param>

--DefinethebasenameforaresourcebundleforI18N-->

javax.servlet.jsp.jstl.fmt.localizationContext<

ApplicationResources<

--Fallbacklocaleifnobundlesfoundforbrowser'

spreferredlocale-->

--Forceasinglelocaleusingparam-name'

javax.servlet.jsp.jstl.fmt.locale'

-->

javax.servlet.jsp.jstl.fmt.fallbackLocale<

en<

--ContextConfigurationlocationsforSpringXMLfiles-->

contextConfigLocation<

classpath:

/applicationContext-resources.xml

/applicationContext-dao.xml

/applicationContext-service.xml

classpath*:

/applicationContext.xml

/WEB-INF/applicationContext*.xml

/WEB-INF/xfire-servlet.xml

/WEB-INF/security.xml

filter>

<

filter-name>

CacheFilter<

/filter-name>

filter-class>

com.opensymphony.oscache.web.filter.CacheFilter<

/filter-class>

init-param>

<

time<

300<

/init-param>

scope<

application<

/filter>

filter-mapping>

url-pattern>

/templet_NOSET/*<

/url-pattern>

/filter-mapping>

--生产环境时开通

/*<

--检测是否有机器人访问

clickstreamFilter<

com.opensymphony.clickstream.ClickstreamFilter<

检测是否有机器人访问-->

encodingFilter<

org.springframework.web.filter.CharacterEncodingFilter<

encoding<

UTF-8<

forceEncoding<

true<

exportFilter<

org.displaytag.filter.ResponseOverrideFilter<

gzipFilter<

net.sf.ehcache.constructs.web.filter.GzipFilter<

--<

lazyLoadingFilter<

org.springframework.orm.hibernate3.support.OpenSessionInViewFilter<

-->

--Use"

org.springframework.orm.jpa.support.OpenEntityManagerInViewFilter"

ifyou'

reusingJPA-->

--

localeFilter<

com.sinosoft.wcms.webapp.filter.LocaleFilter<

rewriteFilter<

org.tuckey.web.filters.urlrewrite.UrlRewriteFilter<

logLevel<

log4j<

securityFilter<

org.springframework.web.filter.DelegatingFilterProxy<

targetBeanName<

springSecurityFilterChain<

sitemesh<

com.opensymphony.module.sitemesh.filter.PageFilter<

staticFilter<

com.sinosoft.wcms.webapp.filter.StaticFilter<

includes<

/scripts/dojo/*,/dwr/*<

struts-cleanup<

org.apache.struts2.dispatcher.ActionContextCleanUp<

/fil

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 初中教育

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1