首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > JAVA > Eclipse开发 >

<html:link用<bean:write name="element"/>做参数有关问题

2011-12-28 
html:link用bean:write nameelement/做参数问题centerjsp:useBeanid listInformation scope

<html:link用<bean:write name="element"/>做参数问题
<center>
        <jsp:useBean   id= "listInformation "   scope= "page "   class= "com.yourcompany.struts.operation.ListInformation "> </jsp:useBean>
          <TABLE   border= "1 "   width=550   cellspacing= "0 "   cellpadding= "0 "     bordercolor= "#CCCCCC "   bgcolor= "#CCCCCC "   style= "TABLE-LAYOUT:fixed ">
                        <TR   bgcolor= "#9999CC ">
                            <TD   align=center   colspan=3   height=40> Please   Enter   Your   Name   And   Your   College </TD>
                        </TR>
                        <TR   bgcolor= "#9999CC ">
                           
                           
                        <TD   align=center>
                            <TABLE   border= "1 "   width= "100% "     height= "100% "   cellspacing= "0 "   cellpadding= "3 "   frame= "void "  
                                  bordercolor= "#CCCCCC "   bgcolor= "#CCCCCC "   style= "TABLE-LAYOUT:fixed ">
                                        <TR>   <TD   align=center   width= "30% "   height=40> Name </TD> </TR>
                              <logic:iterate   id= "element "   name= "listInformation "   property= "nameList ">
                                            <TR   bgcolor= "#FFFFFF ">
                                    <TD   align=center   height= "40 ">
                                    <bean:write   name= "element "/>
                                    </TD>
                                        </TR>
                              </logic:iterate>
                                </TABLE>


                              </TD>
                              <TD   align=center   colspan=2>
                              <TABLE   border= "1 "   width= "100% "     height= "100% "   cellspacing= "0 "   cellpadding= "3 "   frame= "void "
                                        bordercolor= "#CCCCCC "   bgcolor= "#CCCCCC "   style= "TABLE-LAYOUT:fixed ">
                                        <TR   bgcolor= "#FFFFFF ">
                                              <TD   align=center   width= "70% "   height=40   bgcolor= "#CCCCCC "   > College </TD>
                                                      <TD   align=center   height=40   colspan=2   bgcolor= "#CCCCCC "   > Administrate </TD>
                                        </TR>
                              <logic:iterate   id= "element "   name= "listInformation "   property= "collegeList ">
                                            <TR   bgcolor= "#FFFFFF ">
                                    <TD   align=center   height= "40 "   width= "70% ">
                                    <!--bean:write   name= "element "/-->
                                    <bean:write   name= 'element '/>
                                    </TD>
                                    <TD   width= "15% ">
                                   
                                    <html:link   action= "/http2?method=delete&college= ' <bean:write   name= "element "/> ' "> delete </html:link>
                                    <TD   width= "15% "> <html:link   action= "/http2?method=modify "> modify </html:link> </TD>


                                        </TR>
                              </logic:iterate>
                              </TABLE>
                          </TD>
                      </TR>
                </TABLE>

  问题一: <html:link   action= "/http2?method=delete&college= ' <bean:write   name= "element "/> ' "> delete </html:link> 要用 <bean:write   name= "element "/> 作为参数,但按上面这样写时页面提示错误,请问有没有能正确的途径让college的值为bean的属性值,

struts-config.xml配置文件如下
<?xml   version= "1.0 "   encoding= "UTF-8 "?>
<!DOCTYPE   struts-config   PUBLIC   "-//Apache   Software   Foundation//DTD   Struts   Configuration   1.1//EN "   "http://jakarta.apache.org/struts/dtds/struts-config_1_1.dtd ">
<struts-config>
      <data-sources   />
      <form-beans   >
            <form-bean   name= "http2Form "   type= "com.yourcompany.struts.form.Http2Form "   />

      </form-beans>

      <global-exceptions   />
      <global-forwards   >
            <forward   name= "add "   path= "/form/add.jsp "   />
            <forward   name= "delete "   path= "/form/delete.jsp "   />
            <forward   name= "modify "   path= "/form/modify.jsp "   />

      </global-forwards>

      <action-mappings   >
            <action
            attribute= "http2Form "
                  input= "/form/http2.jsp "
                  name= "http2Form "
                  path= "/http2 "
                  parameter= "method "
                  scope= "request "
                  type= "com.yourcompany.struts.action.Http2Action "   />

      </action-mappings>

      <message-resources   parameter= "com.yourcompany.struts.ApplicationResources "   />
</struts-config>

问题二:将上面的 <html:link     改写为 <a   href= "/http2?method=delete&college= <bean   write   name= "element "/> "> delete </a>
提交后不执行DispatchAction的delete方法,而连接到其他页面了,
请问是什么原因啊?

//Created   by   MyEclipse   Struts
//   XSL   source   (default):   platform:/plugin/com.genuitec.eclipse.cross.easystruts.eclipse_3.8.3/xslt/JavaClass.xsl



package   com.yourcompany.struts.action;

import   java.io.BufferedReader;
import   java.io.FileNotFoundException;
import   java.io.FileOutputStream;
import   java.io.FileReader;
import   java.io.IOException;

import   javax.servlet.http.HttpServletRequest;
import   javax.servlet.http.HttpServletResponse;

import   org.apache.struts.actions.DispatchAction;
import   org.apache.struts.action.ActionForm;
import   org.apache.struts.action.ActionForward;
import   org.apache.struts.action.ActionMapping;

import   com.yourcompany.struts.form.Http2Form;


/**  
  *   MyEclipse   Struts
  *   Creation   date:   01-02-2007
  *  
  *   XDoclet   definition:
  *   @struts:action   path= "/http2 "   name= "http2Form "   input= "/form/http2.jsp "   scope= "request "   validate= "true "
  */
public   class   Http2Action   extends   DispatchAction   {

//   ---------------------   Instance   Variables

//   ---------------------   Methods

/**  
  *   Method   execute
  *   @param   mapping
  *   @param   form
  *   @param   request
  *   @param   response
  *   @return   ActionForward
  */
public   ActionForward   add(
ActionMapping   mapping,
ActionForm   form,
HttpServletRequest   request,
HttpServletResponse   response)   {
System.out.println( "in   method   add ");
Http2Form   httpForm   =   (Http2Form)   form;
        String   str= " ";
        if(httpForm.getCollege()!=null){
        try{
        BufferedReader   in=new   BufferedReader(new   FileReader( "e:/temp/DataFactory.txt "));
        int   counter=0;
                String   strLine;
                while((strLine=in.readLine())!=null){
                str+=strLine+ "\r\n ";
                counter++;
               
                }
                if(counter==0)
                counter=1;
          String   strFirst=   counter+ "   :   "+httpForm.getName()+ "   --   "+httpForm.getCollege()+ "\r\n ";
       
        FileOutputStream   out=new   FileOutputStream( "e:/temp/DataFactory.txt ");
        String   newStr=strFirst+str;
        out.write(newStr.getBytes());
        out.flush();
        out.close();
        }catch(FileNotFoundException   e){
        e.printStackTrace();


        }catch(IOException   e1){
        e1.printStackTrace();
        }
        }
        //if(httpForm.getName()!=null)
        //return   (mapping.findForward( "list "));
       
return   (mapping.findForward( "add "));
}
  public   ActionForward   delete(
ActionMapping   mapping,
ActionForm   form,
HttpServletRequest   request,
HttpServletResponse   response)   {
          System.out.println( "in   the   method   delete   from   <html:linkddddd ");
Http2Form   httpForm   =   (Http2Form)   form;
  //request.setAttribute( "form ",httpForm);
 
  System.out.println(httpForm.getCollege()+ "college ");
return   (mapping.findForward( "remove "));
}

}



[解决办法]
第一个问题已经解决
: <html:link action= "/http2?method=delete&college= ' <bean:write name= "element "/> ' "> delete </html:link> 改写成如下
<html:link action= "/http2?method=delete " paramId= "element " paramName= "element "/>

第二个问题可能与我的系统有关系,希望大家参与讨论!

热点排行