首页 新闻 赞助 找找看

SSH框架,如何传递参数?求各路大神花个几分钟帮忙看看,谢谢了。

0
悬赏园豆:20 [待解决问题]

登录页面,输入用户名和密码。进入InfoLoginAction类进行验证,
如果该用户名和密码在数据库存在,并且人员类别等于“维护人员”,进入InfoQueryAction类,取得该人信息,然后进入shenping页面,将该人员部分信息呈现。

问题是从首页,填入的用户和密码是可以传递到第一个Action中的,判断跳转到第二个Action中的时候,就获取不到info对象里的值了。怎么才能在第二个action里获得第一个jsp页面的输入值呢?

首页面(登录页面):

<form id="login" action="infoLogin" method="post" namespace="/">
    <h1>登录</h1>
    <fieldset id="inputs">
        <input name="info.dl_name" type="text" required="required"
            placeholder="Username" tabindex="1" autofocus>
        <input name="info.dl_pass" type="password" required="required"
            placeholder="Password" tabindex="2">
    </fieldset>
    <fieldset id="actions">
        <input type="submit" id="submit" value="Log In">
        <a href="./update.jsp">Forgot your password?</a>
        <a href="./1_login.jsp">Register</a>
    </fieldset>
</form>

struts.xml文件:

    <action name="infoRegister" class="infoRegisterAction">
        <result name="success" type="redirectAction">infoQuery</result>
    </action>
    
    <action name="infoLogin" class="infoLoginAction">
        <result name="weihu" type="redirectAction">
            <param name="actionName">infoQuery</param>
            <!--<param name="info">${info}</param> -->
        </result>
        <result name="zhiban">register.jsp</result>
        <result name="ywsp">register.jsp</result>
        <result name="kfsp">register.jsp</result>
        <result name="err">register.jsp</result>
    </action>
    
    <action name="infoQuery" class="infoQueryAction">
        <result name="success">shenqing.jsp</result>
    </action>
    
    <action name="infoDelete" class="infoDeleteAction">
        <result name="success" type="redirectAction">infoQuery</result>
    </action>
    
    <action name="infoShow" class="infoUpdateAction" method="showInfo">
        <result name="success">update.jsp</result>
    </action>
    
    <action name="infoUpdate" class="infoUpdateAction">
        <result name="success" type="redirectAction">infoQuery</result>
    </action>

applicationContext.xml文件:

   <bean id="infoDao" class="com.dao.InfoDAOImpl">
    <!-- 构造方法注入会话工厂组件sessionFactory -->
    <constructor-arg>
        <ref bean="sessionFactory" />
    </constructor-arg>
</bean>

<bean id="infoService" class="com.service.InfoServiceImpl">
    <!-- 设值注入DAO组件 -->
    <property name="infoDao" ref="infoDao"></property>
</bean>

<bean id="infoRegisterAction"   class="com.action.InfoRegisterAction">
    <!-- 设值注入业务逻辑组件 -->
    <property name="infoService" ref="infoService"></property>
</bean>

<bean id="infoLoginAction" class="com.action.InfoLoginAction">
    <property name="infoService" ref="infoService"></property>
</bean>

<bean id="infoQueryAction" class="com.action.InfoQueryAction">
    <property name="infoService" ref="infoService"></property>
</bean>

<bean id="infoDeleteAction" class="com.action.InfoDeleteAction">
    <property name="infoService" ref="infoService"></property>
</bean>

<bean id="infoUpdateAction" class="com.action.InfoUpdateAction">
    <property name="infoService" ref="infoService"></property>
</bean>

InfoLoginAction.java文件:

public class InfoLoginAction extends ActionSupport {

private static final long serialVersionUID = 1L;
private Info info;
private InfoService infoService;

public Info getInfo() {
    return info;
}

public void setInfo(Info info) {
    this.info = info;
}

// 注入业务逻辑组件
public void setInfoService(InfoService infoService) {
    this.infoService = infoService;
}

public String execute() {
    Info mb = infoService.findByName(info.getDl_name(), info.getDl_pass());
    if (mb != null && mb.getLeibie().equals("维护人员"))
        return "weihu";
    else if (mb != null && mb.getLeibie().equals("值班人员"))
        return "zhiban";
    else if (mb != null && mb.getLeibie().equals("运维审批"))
        return "ywsp";
    else if (mb != null && mb.getLeibie().equals("开发审批"))
        return "kfsp";
    else
        return "err";
    }
}

InfoQueryAction.java文件

    public class InfoQueryAction extends ActionSupport {
 
    private static final long serialVersionUID = 1L;
 
    private InfoService infoService;
    
    private Info info;
 
    public Info getInfo() {
        return info;
    }
 
    public void setInfo(Info info) {
        this.info = info;
    }
 
    public void setInfoService(InfoService infoService) {
        this.infoService = infoService;
    }
 
    public String execute() {
        List<Info> list = infoService.findOne(info.getDl_name());
        ServletActionContext.getRequest().setAttribute("infoList", list);
        return SUCCESS;
    }
 }

shenqing.jsp页面

 <%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
 <%@ page import="java.util.*"%>
 <%@ page import="com.action.TestOrder"%>
 <%@ page import="java.text.SimpleDateFormat"%>
 
 <%@ taglib prefix="s" uri="/struts-tags"%>
 
 <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
 <html>
 <head>
 <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
 <title>操作间入门单申请</title>
 <style type="text/css">
 caption {
    font-size: 36px;
    font-weight: bold;
    line-height: 58px;
 }
 </style>
 <%
    //实例化编号生成类,获取编号填充至编号输入框 
    String number = new TestOrder().getOrderNo();
    //获取当天日期和当前时间,填入表中的填写日期和计划进入时间
    //日期格式
    String dateT = new SimpleDateFormat("yyyy-MM-dd").format(new Date());
    //时间格式
    String dateF = new SimpleDateFormat("HH:mm").format(new Date());
 %>
 </head>
 <body>
    <form action="">
        <table width="1000px" cellspacing="0" align="center">
            <thead>
                <tr>
                    <td colspan="4"><caption>生产操作间进出申请单</caption></td>
                </tr>
                <!-- <tr>
                    <td colspan="3" width="85%" style="text-align: right;"><sub>编号:</sub></td>
                    <td width="15%"><input type="text" name="bianhao"
                        value="" disabled="disabled" size=35 /></td>
                </tr> -->
            </thead>
        </table>
 
        <table width="1000px" border="3" cellspacing="0" cellpadding="0"
            align="center">
            <tbody>
 
                <tr>
                    <td height="30" colspan="4" style="background-color: #AAA;">以下为系统自动填充,无需填写,可根据实际需要调整进入和离开的时间</td>
                </tr>
                <s:iterator value="#request.infoList" id="info">
                    <tr>
                        <td width="200px" height="25">申请单编号</td>
                        <td width="300px"><input type="text" name="id"
                            value="<%=number%>" disabled="disabled" size=38 /></td>
                        <td width="200px">申请日期</td>
                        <td width="300px"><input type="text" name="renyan"
                            value="<%=dateT%>" disabled="disabled" size=38 /></td>
                    </tr>
                    <tr>
                        <td height="25">人员姓名</td>
                        <td><!-- <input type="text" name="riqi" value="#info.xingming"
                            disabled="disabled" size=38 /> -->
                            <s:property value="#info.xingming" /></td>
                        <td>联系方式</td>
                        <td><input type="text" name="renyan" value=""
                            disabled="disabled" size=38 /></td>
                    </tr>
                    <tr>
                        <td height="25">证件号码</td>
                        <td><input type="text" name="zhengjian" value=""
                            disabled="disabled" size=38 /></td>
                        <td>是否为运维人员</td>
                        <td><input type="text" name="yunwei" value=""
                            disabled="disabled" size=38 /></td>
                    </tr>
                    <tr>
                        <td height="25">系统名称</td>
                        <td><input type="text" name="xitong" value=""
                            disabled="disabled" size=38 /></td>
                        <td>申请单位</td>
                        <td><input type="text" name="danwei" value=""
                            disabled="disabled" size=38 /></td>
                    </tr>
                    <tr>
                        <td height="25">计划进入时间</td>
                        <td><input type="time" name="jhjrtime" value="" size=38 /></td>
                        <td>计划离开时间</td>
                        <td><input type="time" name="jhlktime" value="18:00" size=38 /></td>
                    </tr>
                    <tr>
                        <td height="25">实际进入时间</td>
                        <td><input type="text" name="sjjrtime" value=""
                            disabled="disabled" size=38 /></td>
                        <td>实际离开时间</td>
                        <td><input type="text" name="sjlktime" value=""
                            disabled="disabled" size=38 /></td>
                    </tr>
                </s:iterator>
                <tr>
                    <td height="30" colspan="4" style="background-color: #AAA;">以下由申请人填写</td>
                </tr>
                <tr>
                    <td height="25">是否携带设备</td>
                    <td><select name="">
                            <option value="">请选择</option>
                            <option value="笔记本">笔记本</option>
                            <option value="移动硬盘">移动硬盘</option>
                            <option value="U盘">U盘</option>
                            <option value="其他">其他</option>
                    </select></td>
                    <td style="text-align: light;">数量:</td>
                    <td><input name="file_yongtu" type="text" value="" size=38 /></td>
                </tr>
                <tr>
                    <td height="25">是否提取生产数据或文件</td>
                    <td><input name="getdata" type="radio" value="是" />&nbsp;是&nbsp;
                        <input name="getdata" type="radio" value="否" checked />&nbsp;否&nbsp;</td>
                    <td style="text-align: light;">提取文件或数据的用途:</td>
                    <td><input name="file_yongtu" type="text" value="" size=38 /></td>
                </tr>
                <tr>
                    <td height="25">进入操作间具体事由</td>
                    <td><select name="">
                            <option value="">请选择</option>
                            <option value="程序变更">程序变更</option>
                            <option value="数据变更">数据变更</option>
                            <option value="系统投产">系统投产</option>
                            <option value="生产取数">生产取数</option>
                            <option value="查询问题">查询问题</option>
                            <option value="问题分析">问题分析</option>
                            <option value="其他">其他</option>
                    </select></td>
                    <td style="text-align: light;">相关编号或描述:</td>
                    <td><input name="file_yongtu" type="text" value="" size=38 /></td>
                </tr>
                <tr>
                    <td height="25">是否申请特殊权限</td>
                    <td><input name="getperm" type="radio" value="是" />&nbsp;是&nbsp;
                        <input name="getperm" type="radio" value="否" checked />&nbsp;否&nbsp;</td>
                    <td style="text-align: light;">所需权限:</td>
                    <td><input name="perm" type="text" size=38 /></td>
                </tr>
                <tr>
                    <td height="30" colspan="4" style="background-color: #AAA;">以下由审批单位填写</td>
                </tr>
                <tr>
                    <td height="70">信息科技部相关处室审批意见(申请人为非运维人员时需要此项)</td>
                    <td>(信息科技部各处室项目经理负责审批)</td>
                    <td style="text-align: light;">日期:</td>
                    <td></td>
                </tr>
                <tr>
                    <td>应用维护处审批单位意见</td>
                    <td height="70">(应用维护处系统管理员审批)</td>
                    <td style="text-align: light;">日期:</td>
                    <td></td>
                </tr>
            </tbody>
        </table>
 
        <table width="1000px" cellspacing="0" align="center">
            <tfoot>
                <tr>
                    <td colspan="4" width="60%" style="text-align: right;"><input
                        style="background-color: #dee;" name="submit" type="submit"
                        value="提交审批" /></td>
                </tr>
            </tfoot>
        </table>
    </form>
 </body>
 </html>
恨天狂海的主页 恨天狂海 | 初学一级 | 园豆:184
提问于:2019-05-08 15:05
< >
分享
所有回答(1)
0

你试试在你的配置 <param name="actionName">infoQuery</param> 的 infoQuery 后面跟上参数呢; https://blog.csdn.net/ljz520lx/article/details/84014414

画笔灬 | 园豆:920 (小虾三级) | 2019-05-09 13:41
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册