1 First is the page's addpath.jsp
<% @page contenttype= "text/html" pageencoding= "UTF-8"%> <%@ taglib prefix= "C" uri= "http://java.sun.com/jsp/" Jstl/core "%> <%@ taglib prefix=" html uri= "http://struts.apache.org/tags-html"%> <! DOCTYPE HTML PUBLIC "-//w3c//dtd HTML 4.01//en" "HTTP://WWW.W3.ORG/TR/HTML4/STRICT.DTD" >
2 and then the Struts configuration file Struts-config.xml
<!--select action--> <action path= "/selectstationforpath" type= " Cn.osunda.logistics.action.stationmanage.StationAction "scope=" Request "parameter=" Selectstationforpathaction " > </action> <!--to determine whether the route exists action--> <action path= "/judgeexistenceofpath" type= " Cn.osunda.logistics.action.stationmanage.StationAction "scope=" Request "parameter=" Judgeexistenceofpathaction " > </action>
3 The last is the writing of action
Public Actionforward selectstationforpathaction (actionmapping mapping, actionform form, httpservletrequest request, HttpServletResponse response) throws Exception {try {String Startstationid = Request.getparameter ("Startstationid"); List station = Sdi.getobjectsbyproperty (Station.class, "id", "<>", Integer.parseint (Startstationid)); This is the public interface Response.setcontenttype ("Text/html;charset=utf-8") that I write backstage;/set character set PrintWriter out = Response.getwriter ();// The content of the OUT.PRINTLN output is the corresponding data if (station!= null && station.size ()!= 0 in the foreground jquerysuccess:function (data, Textstatus) {for (int i = 0; i < station.size (); i++) {out.println ("<option value= '" + ((station) station.get (i)). GetId () + "' label= '" + ((station) station.get (i)). Getstationname () + "' >"); } else {out.println ("<option value= ' does not select ' label= ' no alternative route ' > ');} out.close (); return null; catch (Exception ex) {ex.printstacktrace (); return Mapping.getinputforward ();}} Public Actionforward judgeexistenceofpathaction (Actionmapping mapping, Actionform form, httpservletrequest request, httpservletresponse response) throws Exception {try {S Tring Startstationid = Request.getparameter ("Startstationid"); String Endstationid = Request.getparameter ("Endstationid"); map<string, object> map = new hashmap<string, object> (); Map.put ("Startstation", Integer.parseint (Startstationid)); Map.put ("Endstation", Integer.parseint (Endstationid)); Path PATH = (path) pdi.getsinglebypropertys (Path.class, map);//This is the public interface that I write backstage response.setcontenttype ("text/html; Charset=utf-8 ");/set character set PrintWriter out = Response.getwriter ();//out.println output is the foreground jquerysuccess:function (data, Textstatus) in the corresponding data if (path!= null) {out.println (1);} else {out.println (0);} out.close (); return null; catch (Exception ex) {ex.printstacktrace (); return Mapping.getinputforward ();}}
4 "Page Preview legend"