| |

VerySource

 Forgot password?
 Register
Search
View: 511|Reply: 2

as a parameter

[Copy link]

2

Threads

7

Posts

8.00

Credits

Newbie

Rank: 1

Credits
8.00

 China

Post time: 2020-1-16 11:40:01
| Show all posts |Read mode
<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%">
Ranch
<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>

 Problem 1: <html: link action = "/ http2? Method = delete&college = '<bean: write name =" element "/>'"> delete </ html: link> /> As a parameter, but the page prompts an error when writing as above.Is there any correct way to make the value of college be the property value of the bean

The struts-config.xml configuration file is as follows
<? 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>

Question 2: Rewrite the above <html: link as <a href = "/ http2? Method = delete&college = <bean write name =" element "/>"> delete </a>
After submitting, the delete method of DispatchAction is not executed, but connected to other pages.
May I ask what is the cause?

// 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 ++;
Ranch
}
if (counter == 0)
counter = 1;
String strFirst = counter + ":" + httpForm.getName () + "-" + httpForm.getCollege () + "\r\n";
Ranch
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"));
Ranch
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);
Ranch
System.out.println (httpForm.getCollege () + "college");
return (mapping.findForward ("remove"));
}

}
Reply

Use magic Report

2

Threads

7

Posts

8.00

Credits

Newbie

Rank: 1

Credits
8.00

 China

 Author| Post time: 2020-2-5 19:45:02
| Show all posts
The first problem has been solved
: <html: link action = "/ http2? method = delete&college = '<bean: write name =" element "/>'"> delete </ html: link>
<html: link action = "/ http2? method = delete" paramId = "element" paramName = "element" />

The second question may be related to my system, I hope everyone will participate in the discussion!
Reply

Use magic Report

2

Threads

7

Posts

8.00

Credits

Newbie

Rank: 1

Credits
8.00

 China

 Author| Post time: 2020-7-3 16:00:01
| Show all posts
The second question should be changed to:
<a href="/http2/http2?method=delete&college=<bean write name="element"/>">delete</a>
The whole problem is solved!
Reply

Use magic Report

You have to log in before you can reply Login | Register

Points Rules

Contact us|Archive|Mobile|CopyRight © 2008-2023|verysource.com ( 京ICP备17048824号-1 )

Quick Reply To Top Return to the list