六狼论坛

 找回密码
 立即注册

QQ登录

只需一步,快速开始

新浪微博账号登陆

只需一步,快速开始

搜索
查看: 44|回复: 0

jquery ajax +struts1.3

[复制链接]

升级  77.33%

46

主题

46

主题

46

主题

秀才

Rank: 2

积分
166
 楼主| 发表于 2013-1-29 12:07:33 | 显示全部楼层 |阅读模式
页面:
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%><html> <head> <script type="text/javascript" src="jquery-1.4.1.js"></script> <script type="text/javascript"> $(document).ready ( function() { $("a").click ( function() { alert("Hello world!"); getHelloxml();    //getH();} ); } ); //ajax调用方法一function getHelloxml(){$.ajax({  type: "POST",   url: "hello.do",   //dataType:"xml",    success: function(xml){     alert( "Data Saved: " +$(xml).text());       }})}//ajax调用方法二function getH(){$.get("hello.do", function(data){  alert("Data Loaded: " + $(data).children().text());});}</script> <body> <a href="#" >helloworld</a> </body> </html> 
 
action
 
/* * Generated by MyEclipse Struts * Template path: templates/java/JavaClass.vtl */package com.yourcompany.struts.action;import java.io.IOException;import javax.servlet.http.HttpServletRequest;import javax.servlet.http.HttpServletResponse;import org.apache.struts.action.Action;import org.apache.struts.action.ActionForm;import org.apache.struts.action.ActionForward;import org.apache.struts.action.ActionMapping;import com.thoughtworks.xstream.XStream;/**  * MyEclipse Struts * Creation date: 02-22-2010 *  * XDoclet definition: * @struts.action validate="true" */public class HelloAction extends Action {/* * Generated Methods *//**  * Method execute * @param mapping * @param form * @param request * @param response * @return ActionForward */public ActionForward execute(ActionMapping mapping, ActionForm form,HttpServletRequest request, HttpServletResponse response) {// TODO Auto-generated method stubXStream xs = new XStream();try {//Message message=new Message();//message.setRest("zhao zhiming ");response.setContentType("text/xml");response.setCharacterEncoding("UTF-8");response.getWriter().write(xs.toXML("你好"));} catch (IOException e) {// TODO Auto-generated catch blocke.printStackTrace();}return null;}} 
struts-config
<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE struts-config PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 1.3//EN" "http://struts.apache.org/dtds/struts-config_1_3.dtd"><struts-config>  <form-beans />  <global-exceptions />  <global-forwards />  <action-mappings >    <action path="/hello" type="com.yourcompany.struts.action.HelloAction" />  </action-mappings>  </struts-config> 
您需要登录后才可以回帖 登录 | 立即注册 新浪微博账号登陆

本版积分规则

快速回复 返回顶部 返回列表