还是关于我的毕业设计例如保存操作,想停留在原页面,或者只是弹出“保存成功”而不需跳转页面要怎么做?谢谢各位为小弟指点迷津

解决方案 »

  1.   

    Ajax
      

  2.   


    第一个jsp用到一个下拉框,里面innerHTML是第二个jsp<%@ page language="java" import="java.util.*" pageEncoding="GB18030"%>
    <%@taglib prefix="s" uri="/struts-tags"%>
    <%@page import="cc.model.Room"%>
    <%
    String path = request.getContextPath();
    String basePath = request.getScheme() + "://"
    + request.getServerName() + ":" + request.getServerPort()
    + path + "/";
    %><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
    <html>
    <head>
    <base href="<%=basePath%>"> <title>管理员登录</title> <script type="text/javascript">
    function save() {
    alert("I am an alert box!!")
    } function loadXMLDoc(str) {
    var xmlhttp; if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari
    xmlhttp = new XMLHttpRequest();
    } else {// code for IE6, IE5
    xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
    }
    xmlhttp.onreadystatechange = function() {
    if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
    document.getElementById("txtHint").innerHTML = xmlhttp.responseText;
    }
    }
    xmlhttp.open("GET", "admin/Admin!listRoom2?buildInfo=" + str, true);
    xmlhttp.send();
    }
    </script> </head>
    <%
    List<String> buildList = (List<String>) session
    .getAttribute("buildList");
    List<Room> roomList = (List<Room>) session.getAttribute("roomList");
    %>
    <body> draftAdd.jsp <select id="s1" onchange="loadXMLDoc(this.value)" style="font-family:Verdana, Arial, Helvetica, sans-serif;">
    <option>
    选择一个栋号
    </option>
    <%
    for (int i = 0; i < buildList.size(); i++) {
    %>
    <option value="<%=buildList.get(i)%>">
    <%=buildList.get(i)%>
    </option>
    <%
    }
    %>
    </select>
    <div id="txtHint"></div> </body>
    </html>
    这是第二个jsp,里面有个action,我想点这个action之后页面不变
    <%@ page language="java" import="java.util.*" pageEncoding="GB18030"%>
    <%@taglib prefix="s" uri="/struts-tags"%>
    <%@page import="cc.model.Room"%>
    <%@page import="cc.dto.DraftInfo"%>
    <%
    String path = request.getContextPath();
    String basePath = request.getScheme() + "://"
    + request.getServerName() + ":" + request.getServerPort()
    + path + "/";
    %><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
    <html>
    <head>
    <base href="<%=basePath%>"> <title>管理员登录</title> <script type="text/javascript">
    function come() {
    alert("I am an alert box!!")
    } function loadXMLDoc(str) {
    var xmlhttp; if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari
    xmlhttp = new XMLHttpRequest();
    } else {// code for IE6, IE5
    xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
    }
    xmlhttp.onreadystatechange = function() {
    if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
    document.getElementById("txtHint").innerHTML = xmlhttp.responseText;
    }
    }
    xmlhttp.open("GET", "admin/Admin!listRoom?buildInfo=" + str, true);
    xmlhttp.send();
    }
    </script> </head>
    <%
    List<String> buildList = (List<String>) session
    .getAttribute("buildList");
    List<Room> roomList = (List<Room>) session.getAttribute("roomList");
    %>
    <body>
    <form action="admin/Admin!saveDraft">
    <%
    if (roomList != null) {
    %>
    <table width="200" border="1">
    <tr>
    <td>
    宿舍号
    </td>
    <td>
    水费
    </td>
    <td>
    电费
    </td>
    </tr>
    <%
    for (Room r2 : roomList) {
    DraftInfo d = new DraftInfo();
    %>
    <tr> <td><%=r2.getName()%></td>
    <td>
    <input type="text" name="water">
    </td>
    <td>
    <input type="text" name="electricity">
    </td>
    </tr>
    <%
    }
    %>
    <input type="submit" value="保存草案" />
    </form>
    </table>
    <%
    }
    %>

    </body>
    </html>继续请教,ajax不太懂
      

  3.   

    跳转到本页面就可以了。或者用ajax进行局部刷新啊。
      

  4.   

    可以在struts2 方法中返回  return null;
      

  5.   

    ajax和跳转到本页面 这是两个最好的方法了
      

  6.   

    都差不多、、、、返回本页、ajax
      

  7.   

    struts2好像不能实现吧。javaScript可以
      

  8.   

    有的,我记得好像有那种在web.xml配置下,然后服务器启动时会初始化action,比如用来处理连接数据库,当你用到时候直接取就好的那种. 记得是在 李刚的ssh整合中看到的