PlumMyLover 2019-05-05 12:14 采纳率: 0%
浏览 376

如何实现js同一页面的值的传递,希望热心大佬帮助一下我,菜鸟实习生,没有c币。。。。。。。。

我现在在做一个退伍军人就业信息管理的模块,现在我要和另一模块退伍军人基本信息连接到一起,基本信息里面没有这个用户我就无法添加就业信息,现在我要做的是点击就业信息模块主界面点击添加信息按钮,跳转到如下界面图片说明

我需要在搜索框输入用户名搜索姓名查询基本信息表内有无该用户,有该用户则会显示在下方,如图图片说明
现在我所想要问的就是,我点击这一条用户信息的确定按钮,要在下方显示的就业信息添加表单里面显示所选的这条基本信息的用户名,如图图片说明
我的问题就是不知道怎么传,上面的查询显示信息我是调用的基本信息的那个主页面查询所有的方法

/**
     * 用户基本信息查询
     */
    public String infoList() throws Exception {
        try {
            if (pageSize == null) {
                pageSize = 10;
            }
            PageUtil pageUtil = new PageUtil(request);
            pageUtil.setPageSize(pageSize);
            // 获取分页的参数
            totalCount = informationService.getTotalCount();
            // 获取分页的参数
            pageUtil.setRsCount(totalCount);
            pageSize = pageUtil.getPageSize();
            int pageCount = pageUtil.getPageCount();
            int currentPage = pageUtil.getCurrentPage();
            // 产生分页的工具条
            pageTool = pageUtil.createPageTool(PageUtil.Text);
            //从基础信息读取所有基础信息
            infoList = informationService.getAll(currentPage, pageSize,name);
            System.out.println(infoList+"##############################################################");
        } catch (RuntimeException e) {
            e.printStackTrace();
        }

        return "infoList";

    }

然后项目用的是ssh框架,公司技术比较老,大佬莫笑,页面请求跳转


@ParentPackage(value = "struts-default")
@Namespace(value = "/")
@Action(value = "employAction", results = {

@Result(name = "list", location = "/admin/system/employ/employ_list.jsp"),
@Result(name = "add", location = "/admin/system/employ/employ_add.jsp"),
@Result(name = "edit", location = "/admin/system/employ/employ_edit.jsp"),
@Result(name = "infoList",location = "/admin/system/employ/employ_add.jsp"),    

})

然后是action的全部,写的比较乱

package com.gyes.employ.action;

import java.io.PrintWriter;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Namespace;
import org.apache.struts2.convention.annotation.ParentPackage;
import org.apache.struts2.convention.annotation.Result;
import org.jfree.data.DataUtilities;
import org.springframework.beans.factory.annotation.Autowired;

import com.gyes.currency.util.BaseAction;
import com.gyes.currency.util.DateUtil;
import com.gyes.currency.util.GsonUtil;
import com.gyes.currency.util.JsonUtil;
import com.gyes.currency.util.MessageBean;
import com.gyes.currency.util.PageUtil;
import com.gyes.employ.bean.Employ;
import com.gyes.employ.service.EmployService;
import com.gyes.system.dept.bean.Dept;
import com.gyes.system.dept.service.DeptService;
import com.gyes.system.dictionary.bean.Dict;
import com.gyes.system.dictionary.serivce.DictService;
import com.gyes.system.information.action.InformationAction;
import com.gyes.system.information.bean.Information;
import com.gyes.system.information.service.InformationService;
import com.gyes.system.information.service.impl.InformationServiceImpl;
import com.gyes.system.user.bean.User;

/**
 * 部门action
 * 
 * @author Administrator
 * 
 */

@ParentPackage(value = "struts-default")
@Namespace(value = "/")
@Action(value = "employAction", results = {

@Result(name = "list", location = "/admin/system/employ/employ_list.jsp"),
@Result(name = "add", location = "/admin/system/employ/employ_add.jsp"),
@Result(name = "edit", location = "/admin/system/employ/employ_edit.jsp"),
@Result(name = "infoList",location = "/admin/system/employ/employ_add.jsp"),    

})

public class EmployAction extends BaseAction{
    @Autowired
    private EmployService employService;
    @Autowired
    private DictService dictService;
    @Autowired
    private InformationService informationService;

    private Employ employ;
    private String[] ids;
    private List<Employ> list;
    private String name;
    private Information information;
    //基础信息集合
    private List<Information> infoList;

    private Map<String, Object> map = new HashMap<String, Object>();

    // 显示数
    private Integer pageSize;
    private Integer totalCount;
    private String pageTool;

    private Integer employId;
    // 字典中的性别集合
    private List<Dict> employwayList;
    private String informationId;

    @Override
    public String execute() throws Exception {
        return null;
    }

    /**
     * 分页查询所有用户(list)
     * 
     * @return
     * @throws Exception
     */
    public String list() throws Exception {
        try {
            if (pageSize == null) {
                pageSize = 10;
            }
            PageUtil pageUtil = new PageUtil(request);
            pageUtil.setPageSize(pageSize);
            // 获取分页的参数
            totalCount = employService.getTotalCount();
            // 获取分页的参数
            pageUtil.setRsCount(totalCount);
            pageSize = pageUtil.getPageSize();
            int pageCount = pageUtil.getPageCount();
            int currentPage = pageUtil.getCurrentPage();
            // 产生分页的工具条
            pageTool = pageUtil.createPageTool(PageUtil.Text);
            list = employService.getAll(currentPage, pageSize,name);
        } catch (RuntimeException e) {
            e.printStackTrace();
        }

        return "list";

    }



    /**
     * 增加就业信息
     */
    public String add() throws Exception {
        employ = employService.getEmploy(employ);
        //从数据字典读取就业方式
        employwayList=dictService.getDictList("dic_employway");
        return "add";
    }



    /**
     * 用户基本信息查询
     */
    public String infoList() throws Exception {
        try {
            if (pageSize == null) {
                pageSize = 10;
            }
            PageUtil pageUtil = new PageUtil(request);
            pageUtil.setPageSize(pageSize);
            // 获取分页的参数
            totalCount = informationService.getTotalCount();
            // 获取分页的参数
            pageUtil.setRsCount(totalCount);
            pageSize = pageUtil.getPageSize();
            int pageCount = pageUtil.getPageCount();
            int currentPage = pageUtil.getCurrentPage();
            // 产生分页的工具条
            pageTool = pageUtil.createPageTool(PageUtil.Text);
            //从基础信息读取所有基础信息
            infoList = informationService.getAll(currentPage, pageSize,name);
            System.out.println(infoList+"##############################################################");
        } catch (RuntimeException e) {
            e.printStackTrace();
        }

        return "infoList";

    }


    /**
     * 同一页面传递用户基本信息的姓名
     */
    public String getInformationName() throws Exception{
        Information list=informationService.getById(informationId);
        System.out.println(list+"kkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkk");
        return list.getInformationname();


    }

     /**
     * 保存新增内容
     * 
     * @return
     * @throws Exception
     */
    public String save() throws Exception {
        try {
            employ.setCrateTime(DateUtil.getSysDateStr());
            Dict dic = new Dict();
            dic.setDictId(employ.getEmployway_id());
            Dict dict = dictService.getById(dic);
            employ.setEmployway_id(dict.getDictId());
            employ.setEmployWay(dict.getValue());
            employService.insertEmploy(employ);
            map.put("success", true);
        } catch (Exception e) {
            e.printStackTrace();
            map.put("success", false);
            map.put("message", e.getMessage());
        }

        GsonUtil.writeToResponse(map, false);
        return NONE;

    }





    /**
     * 进入修改
     * 
     * @return
     */

    public String update() throws Exception {
        employ = employService.getById(employ.getEmployId());
        //从数据字典读取就业方式
        employwayList=dictService.getDictList("dic_employway");


        return "edit";

    }




    /**
     * 保存修改后数据
     * 
     * @return
     */
    public String saveEditEmploy() throws Exception {
        try {
            employ.setModifyTime(DateUtil.getSysDateStr());
            Dict dic = new Dict();
            dic.setDictId(employ.getEmployway_id());
            Dict dict = dictService.getById(dic);
            employ.setEmployway_id(dic.getDictId());
            employ.setEmployWay(dict.getValue());
            employService.updateEmploy(employ);
            map.put("success", true);
        } catch (Exception e) {
            e.printStackTrace();
            map.put("success", false);
            map.put("message", e.getMessage());
        }
        GsonUtil.writeToResponse(map, false);
        return NONE;
    }



    /**
     * 判断用户名是否存在
     * 
     * @return
     */
    public String AjaxName() throws Exception {

        MessageBean messageBean = new MessageBean();
        messageBean.setFlag(false);
        List<Information> data = informationService.getInformationList(employ.getEmployName());
        if (data.size() > 0) {
            messageBean.setFlag(true);
        }
        PrintWriter out = response.getWriter();
        out.print(JsonUtil.objectToJson(messageBean));

        return NONE;
    }


    /*
     * 删除部门
     */
    public String delete() throws Exception {
        try {
            employService.deleAbso(ids);
            map.put("success", true);
        } catch (Exception e) {
            e.printStackTrace();
            map.put("success", false);
            map.put("message", e.getMessage());
        }

        GsonUtil.writeToResponse(map, false);
        return NONE;
    }




public Integer getEmployId() {
        return employId;
    }

    public void setEmployId(Integer employId) {
        this.employId = employId;
    }

    public EmployService getEmployService() {
        return employService;
    }


    public void setEmployService(EmployService employService) {
        this.employService = employService;
    }


    public DictService getDictService() {
        return dictService;
    }

    public void setDictService(DictService dictService) {
        this.dictService = dictService;
    }

    public Employ getEmploy() {
        return employ;
    }


    public void setEmploy(Employ employ) {
        this.employ = employ;
    }


    public List<Employ> getList() {
        return list;
    }


    public void setList(List<Employ> list) {
        this.list = list;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public Map<String, Object> getMap() {
        return map;
    }

    public void setMap(Map<String, Object> map) {
        this.map = map;
    }

    public Integer getPageSize() {
        return pageSize;
    }

    public void setPageSize(Integer pageSize) {
        this.pageSize = pageSize;
    }

    public Integer getTotalCount() {
        return totalCount;
    }

    public void setTotalCount(Integer totalCount) {
        this.totalCount = totalCount;
    }

    public String getPageTool() {
        return pageTool;
    }

    public void setPageTool(String pageTool) {
        this.pageTool = pageTool;
    }

    public String[] getIds() {
        return ids;
    }

    public void setIds(String[] ids) {
        this.ids = ids;
    }

    public List<Dict> getEmploywayList() {
        return employwayList;
    }

    public void setEmploywayList(List<Dict> employwayList) {
        this.employwayList = employwayList;
    }

    public List<Information> getInfoList() {
        return infoList;
    }

    public void setInfoList(List<Information> infoList) {
        this.infoList = infoList;
    }

    public InformationService getInformationService() {
        return informationService;
    }

    public void setInformationService(InformationService informationService) {
        this.informationService = informationService;
    }

    public Information getInformation() {
        return information;
    }

    public void setInformation(Information information) {
        this.information = information;
    }







}

最后是添加页面的代码

<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ taglib uri="/struts-tags" prefix="s"%>

<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>菜单增加</title>
<link href="${pageContext.request.contextPath}/admin/css/box_css.css" rel="stylesheet" type="text/css" />
<link href="${pageContext.request.contextPath}/admin/css/content_css.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="${pageContext.request.contextPath}/admin/script/jquery.js"></script>
<link rel="stylesheet" href="${pageContext.request.contextPath}/admin/css/common.css" type="text/css"/>
<script type="text/javascript" src="${pageContext.request.contextPath}/admin/script/common.js"></script>
<script type="text/javascript" src="${pageContext.request.contextPath}/admin/js/ui.js"></script>
<link href="${pageContext.request.contextPath}/admin/css/style.css" rel="stylesheet" />
<script language="javascript">
function checkEmployName(){


    var formData = jQuery("#form1").serializeArray();
    var saveURL = "<%=path%>/employAction!AjaxName?date="+new Date()+"";
    jQuery.post(saveURL,formData,function(jsonData){
        var message = jsonData.message;
        var flag = jsonData.flag;
          if (flag == true){
              document.getElementById('employName').value='';
              mizhu.alert('', '用户名已经存在,请重新填写!','');
          }

    },"json");

}





  function save(){
    var employName=document.getElementById("employName");
    if(employName.value==''){
            mizhu.alert('', '用户名称不能为空',''); 
        return false;
    }   
    var employIndustry=document.getElementById("employIndustry");
    if(employIndustry.value==''){
            mizhu.alert('', '从事行业不能为空',''); 
        return false;
    }   
    var employ_workTime=document.getElementById("employ_workTime");
    if(employ_workTime.value==''){
            mizhu.alert('', '工作年限不能为空',''); 
        return false;
    }else if(employ_workTime.value>=100){
            mizhu.alert('', '工作年限请输入小于100的数字!!!!','');  
        return false;
    }   
    var employWay=document.getElementById("employWay");
    if(employWay.value==''){
            mizhu.alert('', '就业方式必须选择!!!','');    
        return false;
    }   
    var eduName=document.getElementById("eduName");
    if(eduName.value==''){
            mizhu.alert('', '教育机构名称不能为空','');   
        return false;
    }   
    var companyName=document.getElementById("companyName");
    if(companyName.value==''){
            mizhu.alert('', '公司名称不能为空',''); 
        return false;
    }       
            var formData = jQuery("#form1").serializeArray();
            var saveURL = "<%=path%>/employAction!save";

            $.ajax({
                    type:"POST",
                    url:saveURL,
                    data:formData,  
                    dataType:"JSON",
                    success:function(obj){
                    //alert(obj.success);
                        if(obj.success){
                            $.message("success","新增用户信息成功....");
                            setTimeout(function(){
                                location.href="${pageContext.request.contextPath}/employAction!list";

                            }, 1000);
                        }else{
                            $.message("error",obj.message);
                        }
                    }
                    }); 
                //不提交表单
                return false;

                    }










        function findOut(){
        var name=$("#inputname").val();
        var saveURL = "${pageContext.request.contextPath}/employAction!infoList?name="+name+"";
        if (saveURL!="/employAction!infoList?name=") {
            window.location.href = saveURL; 

            var ifo=document.getElementById("info");
            ifo.style.display="block";
            alert(informationname);


        }else{

        }

        return false;
}; 





        function yes(){
              var emp=document.getElementById("emp");
              emp.style.display="block";
              return false;

}




    </script>
</head>




<body>


<div class="main">
<div class="increase_box">
<div class="increase_list">
<h3><b>就业信息管理</b><span></span></h3>


<div class="increase_main">
<form id="form1"  novalidate="novalidate">
<input type="hidden" id="employId" name="employ.employId" value='<s:property value="employ.employId"/>' />
<input type="hidden" id="informationId" name="information.informationId" value='<s:property value="information.informationId"/>' />
<tr>  <td align="left" valin="middle">






<form action="${pageContext.request.contextPath}/employAction!infoList" method="post">
 <td align="left" valign="middle" style="text-align:right; width:190px;"></td>
            <input type="text" class="input_k2" placeholder="请输入用户名" value="" id="inputname" />
           </td>
  <td align="left" valign="middle" style="text-align:right; width:80px;">
          <a class="byget" href="javascript:" onclick="findOut()">查询</a></td>
      </form>       


</tr>

<table width="96%" border="0" align="center" cellpadding="0" cellspacing="0" class="box_news_show assessment_show" style="display: block" id="info">

 <tr>
        <th width="10%" align="center" valign="middle" class="borderright">ID</th> 
        <th width="10%" align="center" valign="middle" class="borderright">姓名</th>
        <th width="10%" align="center" valign="middle" class="borderright">入伍时间</th>
        <th width="10%" align="center" valign="middle" class="borderright">退伍时间</th>
        <th width="10%" align="center" valign="middle" class="borderright">入党时间</th>
        <th width="20%" align="center" valign="middle" class="borderright">所在单位</th>
        <th width="10%" align="center" valign="middle" class="borderright">状态</th>
        <th width="20%" align="center" valign="middle" class="borderright">身份证号码</th>
        <th align="center" valign="middle" class="borderright">录入人员</th>
        <th width="5%" align="center" valign="middle">操作</th>
      </tr>
<s:iterator value="infoList" status="st">
<tr onMouseOut="this.style.backgroundColor='#ffffff'" onMouseOver="this.style.backgroundColor='#edf5ff'">
<td align="center" valign="middle" class="borderright borderbottom"><s:property value="informationId"/></td>
        <td align="center" valign="middle" class="borderright borderbottom" ><s:property value="informationname"/></td>
        <td align="center" valign="middle" class="borderright borderbottom"><s:property value="enlistmenttime"/></td>
        <td align="center" valign="middle" class="borderright borderbottom"><s:property value="retiredtime"/></td>
        <td align="center" valign="middle" class="borderright borderbottom"><s:property value="partytime"/></td>
        <td align="center" valign="middle" class="borderright borderbottom"><s:property value="unit"/></td>
        <td align="center" valign="middle" class="borderright borderbottom"><s:property value="stats"/></td>
         <td align="center" valign="middle" class="borderright borderbottom"><s:property value="numbers"/></td>
          <td align="center" valign="middle" class="borderright borderbottom"><s:property value="entrypersonnel"/></td>
          <td><input type="submit" value="确定" class="button_1" onclick="yes()"/></td>
        </tr>
</s:iterator>

        </table>




        <table width="96%" border="0" align="center" cellpadding="0" cellspacing="0" class="box_news_show assessment_show" style="display: none" id="emp">
          <tr>
             <td width="20%" class="box_news_show_h3">用户名称: </td>
        <td width="28%" class="box_news_show_h1">
        <input name="information.informaationname" type="text" class="input_k2"  onblur="checkEmployName()" maxlength="20" id="infoname"/> 
            <span style="color:red;" id="infoname">*</span>
        </td>        
            <td width="20%" class="box_news_show_h3">从事行业</td>
            <td width="28%" class="box_news_show_h1">
                <s:textfield name="employ.employIndustry"  id="employIndustry"   class="input_k2" />
                <span style="color:red;" id="employIndustry">*</span> 
             </td>
          </tr>




          <tr>
            <td width="20%" class="box_news_show_h3">工作年限</td>
            <td width="28%" class="box_news_show_h1">
                <s:textfield  name="employ.workTime" class="input_k2" id="employ_workTime"  onkeyup="this.value=this.value.replace(/\D/g,'')"/>&nbsp;年
                <span style="color:red;" id="employ_workTime">*</span> 
            </td>
            <%-- <td width="20%" class="box_news_show_h3">就业方式</td>
            <td width="28%" class="box_news_show_h1">
                <s:select name="employ.employway_id" list="employwayList"  listKey="dictId" listValue="value"  id="employWay" headerKey="" headerValue="请选择" class="input_k2"></s:select>
                <span style="color:red;" id="employ_employWay">*</span> 
             </td>  --%> 
          </tr>





          <tr >
            <td width="20%" class="box_news_show_h3">培训机构名称</td>
            <td width="28%" class="box_news_show_h1">
                <s:textfield   name="employ.eduName" class="input_k2" id="eduName"  />

                <span style="color:red;" id="employ_eduName">*</span> 
            </td>
            <td width="20%" class="box_news_show_h3">公司名称</td>
            <td width="28%" class="box_news_show_h1">
                <s:textfield  name="employ.companyName" id="companyName"  class="input_k2" />
                <span style="color:red;" id="employ_companyName">*</span> 
            </td>
         </tr>



         </table>


</div>
</div>

<div class="increase_bottom"><p>
<input type="button" value="保存" class="button_1" onclick="save()"/>
                <input type="button" class="button_2" value="返回"
                            onclick="history.go(-1)"/>



</p>
</div>
<div class="clear"></div>

</div>
</form>
</body>
</html>

求求各位大佬了,救救孩子吧............................

  • 写回答

2条回答

  • lqiu 2019-05-05 13:13
    关注

    var一个全局变量 就可以调用了

    评论

报告相同问题?

悬赏问题

  • ¥20 求计算赫斯特(Hurst)指数
  • ¥15 delta降尺度计算的一些细节,有偿
  • ¥15 Arduino红外遥控代码有问题
  • ¥15 数值计算离散正交多项式
  • ¥30 数值计算均差系数编程
  • ¥15 redis-full-check比较 两个集群的数据出错
  • ¥15 Matlab编程问题
  • ¥15 训练的多模态特征融合模型准确度很低怎么办
  • ¥15 kylin启动报错log4j类冲突
  • ¥15 超声波模块测距控制点灯,灯的闪烁很不稳定,经过调试发现测的距离偏大