Here is the story, I have a single page application, where I want to call servlet calls from an AJAX object and
index.html
Pre> & lt ;! DOCTYPE html & gt; & Lt; Html & gt; & Lt; Top & gt; & Lt; Meta charset = "ISO-8859-1" & gt; & Lt; Title & gt; Insert title here & lt; / Title & gt; & Lt; Script src = "jquery.js" type = "text / javascript" & gt; & Lt; / Script & gt; & Lt; Script type = "text / javascript" & gt; Function submittext () {var xmlhttp = new XMLHttpRequest (); Xmlhttp.open ("GET", "Submit", true); Xmlhttp.send (); Document.getElementById ("myTextField"). InnerHTML = xmlhttp.responseText; } & Lt; / Script & gt; & Lt; / Head & gt; & Lt; Body & gt; & Lt; Input type = "text" name = "mytext" /> & Lt; Br> & Lt; Button onClick = "submittext ()" & gt; Submit & lt; / Button & gt; & Lt; Br> & Lt; Div id = "myTextField" & gt; & Lt; / Div & gt; & Lt; / Body & gt; & Lt; / Html & gt;
web.xml
& lt; Servlet & gt; & Lt; Servlet-name & gt; Testdogservlet & lt; / Servlet-name & gt; & Lt; Servlet category & gt; Org.springframework.web.servlet.DispatcherServlet & lt; / Servlet-class & gt; & Lt; Load-On-Startup & gt; 1 & lt; / Load-on-startup & gt; & Lt; / Servlet & gt; & Lt; Servlet-mapping & gt; & Lt; Servlet-name & gt; Testdogservlet & lt; / Servlet-name & gt; & Lt; URL pattern & gt; / Presenting & lt; / URL pattern & gt; & Lt; / Servlet-mapping & gt; testdogservlet-servlet
& lt ;? XML version = "1.0" encoding = "UTF-8"? & Gt; & Lt; Bem xmlns = "http://www.springframework.org/schema/beans" xmlns: xsi = "http://www.w3.org/2001/XMLSchema-instance" xmlns: p = "http: // Www. Springframework.org/schema/p "xmlns: reference =" http://www.springframework.org/schema/context "xsi: schema location =" http://www.springframework.org/schema/beans http: / / Www.springframework.org/schema/beans/spring-beans-4.0.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.0. Xsd "& gt; & Lt; Reference: component-scan base-package = "world.hello.mytest" /> & Lt; Bean id = "watchroller" class = "org.springframework.web.servlet.view.InternalResourceViewResolver" & gt; & Lt; Property Name = "View Class" Value = "org.springframework.web.servlet.view.JstlView" /> & Lt; Property Name = "Prefix" Value = "/ Web-NF / JSP /" /> & Lt; Property name = "suffix" value = ".jsp" /> & Lt; / Bean & gt; & Lt; / Bean & gt; MyServlet.java
package world.hello.mytest; Import org.springframework.stereotype.Controller; Import org.springframework.web.bind.annotation.RequestMapping; Import org.springframework.web.servlet.ModelAndView; @ Controller public class MyServlet {Private string saved text; @RequestMapping ("Submit / Submit") Public Models and Submissions () (see new model and view ("text", "barmodelname", "submit successful model object");}} < P> text.jsp $ {barModelName}; This solution works fine, you click the submit button , And it changes the text contained in text.jsp in the div content
The question is, is it unnecessary to dedicate a whole page to this text as a container only Is there a serious solution to do this?