struts multi-module handling problems -> struts experts invited (100 points)

Category: Java EE
 
Boppy
2008-12-30 02:17:11

Sponsored Links
I'm doing a small example is about the struts multi-module processing ... which is more than one struts-config.xml file example .. but I'm working on struts-config.xml., And some of the JSP page is .. Link always find .. I wonder who can give me to talk about this knowledge .. or example ... or information. were OK .. Thanks everyone ...... in some e-mail address : [email protected]

Sponsored Links

yhws520123
2008-12-30 02:24:11
struts1.1 li Since each module can be developed separately, so it is necessary to form in the struts-config.xml configuration file, do not need to write another bean. course , the best on a per-module config files, such as struts-model-config.xml.
<? xml version = "1.0" encoding = "ISO-8859-1"? >

<! DOCTYPE struts-config PUBLIC
"- / / Apache ; Software Foundation / / DTD Struts Configuration 1.1 / / EN "
"

<! -
This is the Struts configuration file for the example application,
using the proposed new syntax.

NOTE: You would only flesh out the details in the "form-bean"
declarations if you had a generator tool that used them to create
the corresponding Java classes for you. Otherwise, you would
need only the "form-bean" element itself, with the corresponding
"name" and "type" ; attributes.
->

<struts-config>
<form-beans>
<form-bean ; name = "investForm"
; type = "org.apache.struts.validator.DynaValidatorForm">
<form-property name = "invest_id" ; type = "java.lang.String" />
<form-property name = "invest_subject" type = "java. lang.String "/>
<form-property name="invest_content" type="java.lang.String"/>
<form-property name="invest_startdate" type="java.lang.String"/>
<form-property name = "invest_enddate" type = "java.lang.String" />
<form-property name = "invest_company" type = "java.lang. String "/>
<form-property name="invest_email" type="java.lang.String"/>
< form-property name = "invest_tel" type = "java.lang.String" />
<form-property name = "invest_fax" type = " ; java.lang.String "/>
<form-property name="invest_address" type="java.lang.String"/>
<form-property name="invest_count" type="java.lang.String"/>
<form-property name = "invest_place" type = "java.lang.String" />
<form-property name = "invest_linkman" type = "java.lang.String" ;/>
<form-property name="invest_memberid" type="java.lang.String"/>
<form -property name = "admin_id" type = "java.lang.String" />
<form-property name = "invest_valid" type = " java.lang.String "/>
<form-property name="pageNum" type="java.lang.String"/>
</ form-bean>
In addition, in the configuration file there are other important parts.
<! - ======= === Global Forward Definitions ============================== ->
<global-forwards>
<forward name="investStageError" path="stageError" />
<forward name="investError" path="backError" />
</ global- forwards>

<! - ========== Action Mapping Definitions =========== =================== ->
<action-mappings>
; <! - Information Front Home ->
<action path = "/ default"
type = "com.invest.action.DefaultAction"
name = "listInvestForm"
validate = "false"
scope = "request">
<forward name = "success" path = " default "redirect =" true "/>
</action>
a362233180
2008-12-30 02:37:14
The following excerpt from friends spiritsl (Dream Dreams Xinlan) replies:

struts1.1 used in application module (Application Modules)

Struts 1.1, a new feature is the application of the concept of modules. Application module allows a single Struts application is divided into several modules, each module has its own Struts configuration file,
JSP page, Action and more. This new feature is medium-sized development team in order to solve the most complained about a problem that, in order to better support parallel development
allows multiple configuration files rather than a single configuration file.

with struts in the development of large-scale projects, the use of this new feature will be a very good choice.

following me a very simple example to demonstrate this feature.

usually be developed in a single module, the most common file directory structure is as follows:
test /
.... / web-inf /
........... / classes
........... / lib
........... / *. tld
........... / struts-config.xml
........... / web.xml
..... ...... / validator-rules.xml
........... / validation.xml
........... ...
.... / js
.... / css
..../main1.jsp (This example uses a simple jsp page)
.... / *. jsp
.....
;

if we add a single module, such as: test1, the most common file directory structure is as follows:
test /
.... / test1 ****
........./main11.jsp (this example uses a simple jsp page)
...... ... / *. jsp ****
.... / web-inf /
........... / classes
.. ......... / lib
........... / *. tld
........... / struts-config. xml
........... / struts-test1-config.xml *****
........... / web.xml
........... / validator-rules.xml
........... / validation.xml
..............
... / js
... / css
.../main1.jsp (this example uses a simple jsp page)
... / *. jsp
... ; ..
[next with "****" for new files or directories]

the following to change a few xml configuration file:
1.struts-config.xml
in the original action-mapping ; increase switchAction such as:
....
....
<action-mappings>

<! - Edit ; user registration ->

<action path = "/ login"
type = "com.ifreeway.rms.v12.action.LoginAction"
scope = "request">
<forward name = "error" path = "/ main1.jsp" />
</action>
<action path = " ;/ login1 "
type =" com.ifreeway.rms.v12.action. LoginAction1 "
scope = "request">
<forward name = "error" path = "/ main1.jsp" />
</action>
; <action path="/switchdo" type="org.apache.struts.actions.SwitchAction"/> ****
; </ action-mappings>
....
....
[side with the "****" for the new features added to the configuration]
2.struts-test1-config.xml
add input to this module actionmapping as follows:
....
; ....
<action-mappings>

<! - Edit user registration ->

<action path = "/ login3"
; type = "com.ifreeway.rms.v12.action.LoginAction2" ;
scope = "request">
<forward name = "error" path = "/ main11.jsp" />
</action>
</ action-mappings>
; ....
....
3.web.xml
....
....
<servlet>
<servlet-name> action </ servlet-name>
<servlet-class> org.apache.struts . action.ActionServlet </ servlet-class>
<init-param>
<param-name> config </ param -name>
<param-value> / WEB-INF/struts-config.xml </ param-value>
< ;/ init-param>
<init-param>
<param-name> config/test1 </ param-name> ; *****
<param-value> / WEB-INF/struts-test1-config.xml </ param-value> ** ***
</ init-param>
<init-param>
<param-name> debug </ param-name>
<param-value> 3 </ param-value>
</ init-param>
<init-param>
<param-name> ; detail </ param-name>
<param-value> 3 </ param-value>
</ init- param>
<load-on-startup> 2 </ load-on-startup>
</servlet>
....
....
[next with "****" for the new features added to the configuration]

we can look to the struts-test1-config.xml add the following code:
<action path = "/ switchdo" type = "org.apache.struts. actions.SwitchAction "/>
because struts1.1 navigation between the modules to be used to org.apache.struts.actions.SwitchAction, if you view the source code can be found struts1.1
org.apache.struts.actions.SwitchAction requires two parameters: prefix and page description of each of the following for this parameter:
these two parameters have to be a "/" at the beginning
prefix simple point is the new name of the module, in this case: test1
page is strutsconfig in the new configuration file to be used actionmapping name on this case: login3.do

Note: If you want to use it, then save the module call prefix = empty string is given below

good conversion method between modules

start Tomcat
http://localhost:8080/test/switchdo.do?prefix=/test1&page=/login3.do
is called struts-test1-config.xml under / login3.do
http://localhost:8080/test/switchdo.do?prefix=&page=/login1.do
is called struts-config.xml under / login1.do
http://localhost:8080/test/switchdo.do?prefix=&page=/login.do
is called struts-config.xml under / login.do
fyeyrtre556
2008-12-30 02:48:49
Configure web.xml file
<servlet>
<servlet-name> action </ servlet-name>
; <servlet-class> org.apache.struts.action.ActionServlet </ servlet-class>
<init-param>
<param-name> config </ param-name>
<param-value> / WEB-INF / struts-config.xml </ param-value> / / ========> is this place, a comma-separated point to other xml file
</ init-param>
<init-param>
<param-name> debug < ;/ param-name>
<param-value> 2 </ param-value>
</ init-param>
<init-param>
<param-name> detail </ param-name> ;
<param-value> 3 </ param-value>
</ init-param>
<load-on-startup> 2 </ load-on-startup>
</servlet>
yunfan5
2008-12-30 02:54:04
speaks so carefully, and I'll stick you an example
index.jsp:

<% @ page language = "java" contentType = "text / html; charset = GB2312 "%>
<% @ taglib uri =" / WEB-INF/struts-html.tld "prefix =" html " %>
<html:html>

<body>
<table>
<html: form action = "Member" ; name = "MemberForm" type = "struts.MemberForm">
<tr>
<td> Name: </td>
<td> <html:text property="name"/> </td>
</tr>
<tr>
<td> Password: </td>
<td> <html:password property="password"/> </td>
</tr>
<tr>
<td> <html:submit value=" "/> </td>
</tr>
</ html: form>
</table>
</body>
</ html: html>

Action:

package struts;

import javax.sql.DataSource;
import java.sql.Connection;
import java.sql.Statement;
import java.sql.ResultSet;
import java.sql.SQLException;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

public class MemberAction extends Action {

public String getQuote (HttpServletRequest ; request, String name, String password) {

String qq = null;
Connection ; conn = null;
Statement stmt = null;
ResultSet rs = null;
DataSource data = null;

try {
data = getDataSource (request);
; conn = data.getConnection ();
stmt = conn.createStatement ();
rs = stmt.executeQuery ( "select * from member where" + "net_name = '" + name + "' and" +
"password = '" ; + password + "'");

if (rs.next ()) {
String s = ; "";
s = rs.getString ("e_mail");

qq = new String (s);

System.err.println ("qq:" + qq);
}
else {
System.err.println ("Name not found returning null");
}
;}
catch (SQLException e) {
System.err.println (e.getMessage ());
}
finally {
if (rs! = null) {
try {
rs.close ( );
}
catch (SQLException sqle) {
System.out.println (sqle.getMessage ());
}
rs = null;
}

if (stmt ;! = null) {
try {
stmt.close ();
}
catch (SQLException sqle) {
System.out.println (sqle.getMessage ());
}
stmt = null ;
}

if (conn! = null) {
try {
conn.close ();
}
catch (SQLException sqle) {
System.out.println (sqle . getMessage ());
}
conn = null;
}
}
return qq;
}

public ActionForward execute (ActionMapping mapping, ActionForm form,
; HttpServletRequest request,
; HttpServletResponse response)
; ; throws IOException, ServletException {
/ ** @ todo: complete the business logic here, this is just a skeleton. * /
String s = null;

String target = new String ("success");

if (form! = null) {
; MemberForm memberForm = (MemberForm) form;

String name = memberForm.getName ();
String password = memberForm.getPassword ();

; s = getQuote (request, name, password);
}

if (s == null) {
target = new String ("failure");
}
else {
request.setAttribute ("PRICE", s);
}
return (mapping.findForward (target));
}
}

Form:

package struts;

import javax.servlet.http.HttpServletRequest;
import org.apache.struts . action.ActionForm;
import org.apache.struts.action.ActionMapping;

public class MemberForm extends ActionForm {

private int id;
private String name = null;
private String password = null;
private String real_name = null;
private String sex = null;
private String e_mail = null;
private String qq = null;
private String descri = null;
;
public int getId () {
return id;
}

public void setId (int id) {
this.id = id;
}
;
public String getName () {
return (name);
}

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

public String getPassword () {
return (password);
;}

public void setPassword (String password) {
this.password = password;
}

public String getRealName () {
return (real_name);
;}

public void setRealName (String real_name) {
this.real_name = real_name;
}

public String getSex () {
return (sex);
;}

public void setSex (String sex) {
this.sex = sex;
}

public String getEMail () {
return (e_mail);
;}

public void setEMail (String e_mail) {
this.e_mail = e_mail;
}

public String getQq () {
return (qq);
;}

public void setQq (String qq) {
this.qq = qq;
}

public String getDescri () {
return (descri);
;}

public void setDescri (String descri) {
this.descri = descri;
}

public void reset (ActionMapping actionMapping, HttpServletRequest httpServletRequest) {
this. name = null;
this.password = null;
this.real_name = null;
this.sex = null;
this.e_mail = null;
; this.qq = null;
this.descri = null;
}
}

quote.jsp:

<% @ page contentType = "text / html; charset = GB2312"%>
<html>
<head>
<title>
qoute
</title>
</head>
<body bgcolor = "# ffffff">

<table width = "500"
booder = "0" cellspacing = "0" cellpadding = "0">
<tr>
<td>
<h1> <% = request.getAttribute ("PRICE")%> </ h1>
</td>
</tr>
</table>
</body>
</html>
wuzuoya
2008-12-30 02:57:47
you first put the structure STRUTS understand, there is information inside the configuration file is what it means, how to apply these information can
guobaodi
2008-12-30 03:10:14
without swichAction okay ...
structure:
WebRoot
- --- test
-------- struts-config. xml
-------- test. jsp
--- WEB-INF
--------- struts. config.xml
--------- web. xml
this structure .....
zhujkforjob
2008-12-30 03:17:41
Research medium. . . .
chenya123
2008-12-30 03:23:47
What do you mean .. can not understand .. Brother specific point ah ... My web.xml file looks like this ..
<? xml version = "1.0 "encoding =" UTF-8 "?>
<! DOCTYPE web-app PUBLIC" - / / Sun Microsystems, Inc. / / DTD Web Application ; 2.3 / / EN ""
<web-app>
<servlet>
<servlet-name> action </ servlet-name>
< ; servlet-class> org.apache.struts.action.ActionServlet </ servlet-class>
<init-param>
<param-name> config </ param-name>
<param-value> / WEB-INF/struts-config.xml </ param-value>
</ init-param>
<init-param>
< param-name> config / regedit </ param-name>
<param-value> / WEB-INF/struts-config-regedit.xml </ param-value>
</ init- param>
<init-param>
<param-name> config / client </ param-name>
<param-value> / WEB-INF/struts-config- client.xml </ param-value>
</ init-param>
<init-param>
<param-name> debug </ param-name>
<param-value> 3 </ param-value>
</ init-param>
<init-param>
<param-name> detail </ param- name>
<param-value> 3 </ param-value>
</ init-param>
<load-on-startup> 0 </ load-on-startup> ;
</servlet>
<servlet-mapping>
<servlet-name> action </ servlet-name>
<url-pattern> *. do < ;/ url-pattern>
</ servlet-mapping>
<welcome-file-list>
<welcome-file> standSys.jsp </ welcome-file>
</ welcome-file-list>
<taglib>
<taglib-uri> / WEB-INF/struts-html.tld </ taglib-uri>
< ; taglib-location> / WEB-INF/struts-html.tld </ taglib-location>
</taglib>
<taglib>
<taglib-uri> / WEB -INF/struts-bean.tld </ taglib-uri>
<taglib-location> / WEB-INF/struts-bean.tld </ taglib-location>
</taglib>
<taglib>
<taglib-uri> / WEB-INF/struts-logic.tld </ taglib-uri>
<taglib-location> / WEB-INF/struts- logic.tld </ taglib-location>
</taglib>
<taglib>
<taglib-uri> / WEB-INF/struts-template.tld </ taglib- uri>
<taglib-location> / WEB-INF/struts-template.tld </ taglib-location>
</taglib>
<taglib>
< ; taglib-uri> / WEB-INF/struts-tiles.tld </ taglib-uri>
<taglib-location> / WEB-INF/struts-tiles.tld </ taglib-location>
</taglib>
</ web-app>

because my other files are in different directories below ... but not in the same directory ....

you say this is it ..

<init-param>
<param-name> config </ param-name>
< ; param-value> / WEB-INF/struts-config.xml, / WEB-INF/struts-config-regedit.xml, / WEB-INF/struts-config-client.xml </ param-value>
</ init-param>
luoqiming1981
2008-12-30 03:43:23
out of the question now is when I link the problems ......

I have a regeditAction .
me a link to the previous page is so <html:link page="/regedit"> regedit </ html: link>
struts-config.regedit.xml inside Content is this ...
<form-beans>
<form-bean name = "regeditForm" type = "com.regedit.forms.regeditForm" ;/>
</ form-beans>

<action-mappings>
<action
attribute = "regeditForm"
name = "regeditForm"
path = "/ regedit"
scope = "request"
type = "com.regedit.actions.regeditAction"
unknown = "false"
validate = "false">
<forward
name = "success"
path = "/ regedit / regedit.do" ;
redirect = "false"
contextRelative = "false" />
</action>
</ action-mappings>
wangjb65
2008-12-30 03:52:39
less of what ... but also what kind of configuration .. please help younger ......... Online ah ..!!!!!
lianlei0913
2008-12-30 04:07:29
Brother ............ listed above questions and your code does not seem the same thing out of it ...........

There are no examples of the above mentioned multi-module ah ..... yes please .... do not stick to the above, then you can talk about ...

really like you as an example Many online .....
ynpeacesky
2008-12-30 04:16:19
ZT:
about Struts Action_mapping
information by the application logic to determine ActionMapping
ctionMapping for the entire application to determine the "line map "in the configuration file struts-config.xml right ActionMapping be defined by forwarding the request (forward) to streamline application processes, determine the application for each user request corresponding action.

We usually develop Struts, you should first spend out of its simple flowchart, the corresponding Action that FormBean, which will link to the page, or Forward to which Action. Basically With this sketch, we write Action_mapping, it will save a lot of time and remove many unnecessary mistakes. then in the process of developing code for the specific step by step improve our Struts-config.xml.

When an Action class finished with a logical business, it returns forward is defined in ActionMapping An Action returns a variety of forward entirely possible, although generally only define an Action related to several forward. So, if there are multiple Action are likely to return with a forward, then it can be defined as a global forwarding (global forward). As follows:
<! - ========== Global Forward definitions ->
<global-forwards>
<! - an error of forward ->
<forward name="error" path="/Errorpage.jsp"/> ;
</ global-forwards>
This is also equivalent to a global function or variable, etc., in the entire logic plays a role in running once an Action when necessary forward error This <forward name="error" path="/Errorpage.jsp"/> will have an effect, be linked to Errorpage.jsp.

us look at the properties of elements related to the Action
<! - ========== Action Mapping definitions ->
<action-mappings>
<! - <action> elements related properties ->
<! -
specific content, please take a look at org.apache.struts.action.ActionMapping related documents, you will know more
path - the current Action corresponding user request URI path
type - to achieve the current Action of the full Java class name
name - used in the current Action The ActionForm's name, the specific information in the configuration file elsewhere otherwise defined in detail
unknown - If the property is set to true, then the statement is this Action will handle the entire application is not found in all the appropriate Action processing requests, of course, an application system there will only be an Action unknown attribute can be set to true
scope - Action in the lifetime of ActionForm used, you can "request" or "session", with the survival of the setting, the Action will be created at the corresponding time
input - Action in the relevant ActionForm obtain user input input page, when set to Auto ActionForm validating input data, found that illegal data returns an error, it will return the page
validate - if this property is true before the action in the Action corresponding ActionForm validate method will automatically be called, generally used to validate user input data
forward elements - define the current Action related ActionForward
->

struts-config. xml is the MVC model of Controller.
and jsp page in Struts MVC pattern is the View.
Action & ActionFormBean MVC pattern is the Module.
so we should spend more time In struts-config.xml above, to ensure that each define an Action and its related definitions is consistent with the needs of the application.

Since Struts Action class will be invoked by the. So it should be the main method is an abstract method inherited by the subclass for each specific implementation, or in which the Action will do all to do some general mechanism of the Chinese meaning of some of the parameters.
Parameter mapping : its type is ActionMapping, doing jumps in the Action choose
parameters actionForm: from the Struts HTTP requests under this data to populate the ActionForm object
complete parameter request: This Action all processing of this HTTP request (object)
parameter response: This Action output data to use HTTP response (object)

mycityhot
2008-12-30 04:21:21
thank the the help of colleagues .... you .... have MSN or QQ can add you specifically talk about this problem? brother now doing a project .. and struts to learn a few days .. but there are too more applications there are still some problems .... Please also give exhibitions ..... Of course you say so much .. very helpful to me ... the problem is that there is no link to get.
wheat198
2008-12-30 04:24:38
Oh I am also a graduate student, only one week into the company more than
MSN: [email protected]
QQ: 16639336
Domain and server ip had changed since 8/23/2013. Suspend the user registration and posts for program maintenance.