簡體   English   中英

在另一個jsp struts 2中使用jsp

[英]jsp in another jsp struts 2

第一個問題:我有一個jsp,其中有兩個選項卡,對於第二個選項卡,我包含了struts include標簽。 當我打開第二個選項卡並執行操作時,第二個選項卡表單值未傳遞給該操作。

第二個問題 :在select標簽中,我已經填充了列表,但是它是預填充的,意味着所有選項都如select =“ selected”一樣來

制作選項卡的主要jsp

<!-- admin first tab starts here -->
    <form action="saveRolesAndPermissions" method="post">
    <table align="center">
        <tr>
            <td ><s:text name="FTID" ></s:text></td>
            <td ><s:textfield id="FTID" name="ft_id">
                </s:textfield></td>
                <td><input type="button" value="validate" onclick="userPresent()"></td>
        </tr>

    </table>

            <table>
                <tr>
                    <td>First Name</td>
                    <td><input id="first_name" type="text" readonly onkeydown="return false"></td>
                    <td>Last Name</td>
                    <td><input id="last_name" 
                        type="text" readonly onkeydown="return false"></td>
                    <td>Email-Id</td>
                    <td><input id="mail_id" type="text"
                        readonly onkeydown="return false"></td>
                </tr>
            </table>


            <table align="center">
        <tr>
            <td><s:text name="ROLES"></s:text></td>
            <td></td>
            <td></td>
        </tr>
        <tr>
            <td><s:text name="Available Roles"></s:text></td>
            <td></td>
            <td><s:text name="Assigned Roles"></s:text></td>
        </tr>
        <tr>
            <td><s:select id="roles" name="availableRole"
                    multiple="true" list="availableRole"></s:select></td>
            <td><input type="button" value="&gt" onclick="move_list_items('roles','assignedroles');"/><input
                type="button" value="&lt" onclick="move_list_items('assignedroles','roles');"/></td>

            <td><s:select id="assignedroles" name="assignedRole" multiple="true"
                    list="{}" >
                    </s:select></td>
        </tr>
    </table>
    <br /> <br /> <br />
    <table>
        <tr>
            <td><s:text name="Permissions"></s:text></td>
            <td></td>
            <td>&nbsp;</td>
        </tr>
        <tr>
            <td><s:text
                    name="Available Permissions"></s:text></td>
            <td></td>
            <td><s:text name="Assigned Permissions"></s:text></td>
        </tr>
        <tr>
            <td><s:select id="permissions" multiple="true"
                    name="availablePermission" list="availablePermission" headerValue=""></s:select></td>
            <td><input
                type="button" value="&gt" onclick="move_list_items('permissions','assignedpermissions');"/><br /> <input type="button" 
                value="&lt" onclick="move_list_items('assignedpermissions','permissions');" /></td>
            <td><s:select id="assignedpermissions" multiple="true" name="assignedPermission"
                    list="{}" ></s:select></td>
        </tr>
    </table>
    <br /> <br />

            <table align="center" style="width: 25%;">
                <tr>
                    <td><s:if test="hasActionMessages()">
                            <div class="welcome" style="list-style:none">
                                <s:actionmessage />
                            </div>
                        </s:if></td>
                </tr>
            </table> 


            <table>
        <tr>
            <td><s:submit 
                    value="save"onclick="saveRole();return false;"></s:submit></td>
            <td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input type="button" name="close"
                value="close" /></td>
        </tr>
        <tr>
            <td></td>
            <td></td>
        </tr>
    </table>
    </form>


<!-- second tab for modify roles -->
<div id="content02" class="content" >
<s:include value="../asp/aspAdminModify.jsp"></s:include>
</div>
<!-- /second tab ends here -->

包含jsp

<form action="grantedRolesAndPermissions" method="post">
    <table>
        <tr>
            <td><s:text name="FTID" ></s:text></td>
            <td><s:textfield id="modify_FTID" name="modifyftid">
                </s:textfield></td>
                <td><s:submit 
                    value="search" onclick="search();return false;"></s:submit>
                </td>
        </tr>

    </table>

Bean的第一個標簽

private String ft_id;
    private ArrayList<String> availableRole;
    private ArrayList<String> availablePermission;
    private ArrayList<String> assignedRole;
    private ArrayList<String> assignedPermission;
//getters and setters

第一個標簽的操作

public class ASPadmin extends ActionSupport implements ServletRequestAware, ModelDriven<ASPAdminBean>{

    /**
     * 
     */
    private static final long serialVersionUID = 1L;
    private AdminASPService aspService = new AdminASPService();
    private HttpServletRequest request = ServletActionContext.getRequest();
    private HttpServletResponse response = ServletActionContext.getResponse();
    public CMTUser cmtuser;
    private ASPAdminBean aspAdminBean = new ASPAdminBean();


    //getters and setters



    public String populateRolesAndPermissions() throws Exception
    {
        /*aspAdminBean=new ASPAdminBean();*/
        aspAdminBean.setAvailableRole(aspService.getRolesList());
        aspAdminBean.setAvailablePermission(aspService.getPermissionsList());
        return SUCCESS;

    }

    public String saveRolesAndPermissions() throws Exception
    {

        User user = CMTUser.getUser(request);
        String login = user.getUserId();
        String[] temp = login.split("\\.");
        String abcfinal = temp[0].substring(0, 1).toUpperCase()
                + temp[0].substring(1);
        String deffinal = temp[1].substring(0, 1).toUpperCase()
                + temp[1].substring(1);
        String name = abcfinal + " " + deffinal;
        System.out.println("name ==============>" + name);
        String id = aspService.saveRolesPermissions(aspAdminBean,name);
        System.out.println("id=======>"+id);
        if("Y".equals(id)){
            addActionMessage("Record Inserted Successfully");
            populateRolesAndPermissions();
            return SUCCESS; 
        }
        else{
            return ERROR;
        }

    }

    @Override
    public String execute() throws Exception {
        String url = request.getRequestURL().toString();
        String[] actionArray = url.split("/");
        String event = null;
        String forward = SUCCESS;
        for (int i = 0; i < actionArray.length; i++) {
            event = actionArray[i];

        }
        System.err.println(event);
        try {


            if (event.equals("aspAdmin.action")) {

                    populateRolesAndPermissions();

            }
        }catch (Exception e) {
            e.printStackTrace();
        }
        return SUCCESS;
    }

    @Override
    public void setServletRequest(HttpServletRequest req) {
        this.request = req;

    }

    @Override
    public ASPAdminBean getModel() {
        // TODO Auto-generated method stub
        return aspAdminBean;
    }

}

第二個標簽的bean

public class ASPAdminModifyBean {
    private String modifyftid;
    private  String  aspmodifyassignedRole;
    private String  aspmodifyassignedPermission;
    private String createddate;
    private String createdby;
    private String updateddate;
    private String updatedby;
    private String username;
    private ArrayList<String>  modifyavailableRole;
    private ArrayList<String>  modifyavailablePermission;
    private  ArrayList<String>  modifyassignedRole;
    private ArrayList<String>  modifyassignedPermission;
//getters and setters   

第二個選項卡的操作

public class ASPadminModify extends ActionSupport implements ServletRequestAware, ModelDriven<ASPAdminModifyBean> {



    private AdminASPService aspService = new AdminASPService();
    private GetRolePermissionListInt[] roleVO;
    private HttpServletRequest request = ServletActionContext.getRequest();
    private HttpServletResponse response = ServletActionContext.getResponse();
    private ASPAdminModifyBean modify = new ASPAdminModifyBean();
    GetRolePermissionListInt role;

    //getters and setters for the above


    public String grantRolesPermissions(){
        System.out.println("enter the grant roles and permissions");
        String tab2="modify";
        boolean id;
        HttpServletRequest request=getRequest();
        HttpSession session=request.getSession();
        session.setAttribute("tabs",tab2 );
        role=aspService.getGrantedRolesAndPermissions(modify);
        System.out.println("assigned roles===================>"+role.getAssignedRoles());
        modify.setAspmodifyassignedRole(role.getAssignedRoles());
        modify.setAspmodifyassignedPermission(role.getAssignedPermissions());
        modify.setCreatedby(role.getCreatedBy());
        modify.setCreateddate(role.getCreatedDate());
        modify.setUpdatedby(role.getUpdatedBy());
        modify.setUpdateddate(role.getUpdatedDate());
        modify.setUsername(role.getUserName());
        modify.setModifyftid(role.getFtid());
        System.out.println("assigned permissions==============>"+role.getAssignedPermissions());
        System.out.println("updated by=================>"+role.getUpdatedBy());
        System.out.println("update date=================>"+role.getUpdatedDate());
        System.out.println("created by===================>"+role.getCreatedBy());
        System.out.println("created date=====================>"+role.getCreatedDate());
        System.out.println("ftid=============================>"+role.getFtid());
        System.out.println("user name===========================>"+role.getUserName());
        System.out.println("ftid=============>"+role.getFtid());
        if(role!=null){
            return SUCCESS;
        }else{
            return ERROR;
        }

    }


    @Override
    public void setServletRequest(HttpServletRequest arg0) {
        // TODO Auto-generated method stub

    }

    @Override
    public ASPAdminModifyBean getModel() {
        // TODO Auto-generated method stub
        return modify;
    }

}

好吧,代碼又增長了:)

開始於:

  • 將您的ArrayList聲明更改為List(在兩個bean中,並重新生成getter和setter);
  • 改變你的請求,響應和會話的方式,通過使用Struts2的感知 s接口它們的制定者,用里面的代碼)

然后,如果仍然不起作用,請更好地描述“值沒有傳遞給Action”的含義,並考慮發布攔截器堆棧配置。

希望有幫助...

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM