The perfect combination of Ajax Jquery struts!

Source: Internet
Author: User

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"

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.