Professional Documents
Culture Documents
Java Review
Flow charts: http://jdurrett.ba.ttu.edu/Resources/Programming/index.html
Basic MyEclipse
Chapter by Chapter
Debugging in MyEclipse
c) Tomcat servlet container (The following assumes individual installs not the All-in-one MyEclipse)
i) Install java jdk first
(1) I am using the 1.7.0x version in Linux & 1.6.0 in Windows
(2) http://java.sun.com
(3) Important: make sure the versions (32bit or 64bit) of java & Eclipse match
ii) Now install Apache Tomcat
(1) http://tomcat.apache.org
(2) Use only the release builds
(3) If you have errors installing the first time, set an environment variable
JAVA_HOME=”C:\where\ever\jdk\is” then try again
iii) Then install your IDE
(1) If using eclipse and MyEclipse (docs are here)
(a) Eclipse (3.4 Works Now) first: http://www.eclipse.org/
if you have zip problems get WinZip
(b) then MyEclipse (8.0GA): http://www.myeclipseide.com
if you have install problems use the manual install version
(c) Put jdk bin directory at first of PATH
(b) include Directives are used to insert text and/or code at JSP translation time
(i) <$@ include file=”somefile.jsp” %>
(c) taglib Directive says that the including page uses a custom tag library
(i) <%@ taglib url=”tagLibraryURL” prefix=”tagXMLprefix %>
(ii) <tiles:putlist ....
(e) <jsp:param name=”paramName” value=”someParamValue” /> provides parameters for include, forward, &
plugin
(f) <jsp:include page=”url” flush=”true /> evaluated each time page is requested as opposed to include
directive include.jsp (48)
e) JavaServer Faces
i) Horstmann Core JSF links
3) Struts – Apache User Guide
a) jakarta.apache.org --> struts.apache.org --> why are we using struts 1.1 ???
-----------------------------------------------------------
(5) Note the names of the methods. You MUST the JavaBean standard naming convention
==================================================
4) Actions & ActionServlet
The Controller components: ActionServlet.class, Action.class, Plugins (which we will mostly ignore), & the
RequestProcessor
a) ActionServlet
b) Action Class
The most common component in struts webapps
c) Plugins
i) Must implement the org.apache.struts.action.Plugin interface
ii) Useful for allocating resources (properties files), setting up jdbc or jndi, & other init functions
ex: tiles.TilesPlugin & validator.ValidatorPlugin
iii) Create a class that implements the Plugin interface
iv) Add an empty constructor, a init(ActionServlet, ModuleConfig), & a destroy() method
v) Put what you want to happen at application startup in the init method
We will use logging from http://logging.apache.org/log4j/1.2/index.html & reading a properties file
vi) Add the <plug-in className=”ch04Plugin” /> to the main struts-config.xml file
Please note from the example that this must be the last element in the config file
vii) Put controller element in struts-config file after action-mapping and before message-resources
(listing 4.3 pg 89)
d) Logging with log4j
i) Logging in any webapp is critical to track problems, use of the system, &/or development progress
ii) System.out.println or err.println can be used but is not as effective
iii) Get the log4j jar file from the apache.org web site above
iv) Put the jar file in your project’s WEB-INF/lib folder and click Refresh in eclipse
v) The online docs at the apache site are the best source of info on the properties file and its loggers,
appenders, conversion patterns, log levels, etc
vi) Please note priority of log levels is debug < info < warn < error < fatal and that incoming log level
request must be equal to or greater than the system loggers level set in the properties file to be
printed
log4j.appender.fileout.File=/home/durrett/temp/durrett.log
log4j.appender.fileout.MaxFileSize=10MB
log4j.appender.fileout.MaxBackupIndex=10
log4j.appender.fileout.layout=org.apache.log4j.PatternLayout
log4j.appender.fileout.layout.ConversionPattern=%d %-5p %-30.30c{1} %x - %m%n
-- The next part assumes you are creating a Plugin to initialize your own logging system ---
ix) Create a log4j.properties (log4j.pjsprops) file and put it in your WEB-INF folder
Please note that putting the log4j.properties file in WEB-INF/classes overrides the default logger
x) Initialize a static Logger object in your PlugIn class
public static Logger pjsLog = Logger.getLogger(“A1”);
xi) Configure the pjsLog object
String fullPathtoYourWebapp = servlet.getServletContext().getRealPath("/");
PropertyConfigurator.configure(fullPathtoYourWebapp + “/WEB-INF/log4j.pjsprops”);
xii) Anywhere in your application that you want to log use the instructions from viii above and,
Logger pjsLog = Logger.getLogger("A1"); // get the specific logger you created in your plugin
pjsLog.info("Symbol: " + sStk);
e) Properties files
i) Setup a properties file. This can be xml or java properties (the version I use in the pjs project) type
SYSTEM_TITLE=Professional Jakarta Struts
ii) Save the file in the WEB-INF folder of your app
iii) Create a file object
File file = new File(fullPathtoYourWebapp + "/WEB-INF/props.txt");
iv) Open a FileInputStream: FileInputStream fis = new FileInputStream(file);
v) Load the properties: properties.load(fis);
vi) Add the properties to the ServletContext (the webapplication memory space)
ServletContext context = servlet.getServletContext();
context.setAttribute(“PROPERTIES”, properties);
vii) You can use the set properties anywhere in your webapp like this:
ServletContext context = request.getSession().getServletContext();
Properties rProperties = (Properties)context.getAttribute("PROPERTIES");
String sTitle = rProperties.getProperty("SYSTEM_TITLE");
f) RequestProcessor
When customizing ActionServlet this is where to start
============================================
5) Advanced Action Classes
a) Design Notes
i) Limit the “business logic” in your jsp
(1) jsp's are for user views,
they DO NOT talk to the model, they only display pieces of it
(2) Actions are for control & select the next view not the jsp
(3) the struts-config.xml file controls ALL system flow
(4) Helper object models implement business logic
struts-config.xml:
<action path=”/pagelink”
parameter=”/somepage.jsp”
type=”org.apache.struts.actins.ForwardAction”
/>
iii) <global-forwards>
<forward name="ch05" path="/ch05/index.jsp"></forward>
</global-forwards>A
---------------------------------------------------------------------------------------
d) DispatchAction
i) Helps to “condense” simple actions into one action class
ii) Steps:
(1) Create an action handler that extends DispatchAction (pg 98)
(2) Create a method in the new class for each logical action
(3) Create an action mapping for your new class in struts-config.xml
This mapping should use the parameter attribute to specify the http request parameter that will
care the method name (pg 99)
(4) Pass the action an appropriate request parameter in your jsp code (pg 99)
e) DynaLookupForm
a) Building a View
A view is a combination of JSP's, Tag libraries, and Form beans
optional attributes
(a) focus=”name of initial focus attribute”
optional attributes
(a) value=”initial value of attribute”
(b) readonly=”true if desired”
(5) struts-config
(3) struts-config
(1) Controller creates (or retrieves) instance of LoginForm & stores it in session
(2) Controller calls LoginForm.reset()
(3) Controller populates LoginForm object with data from html:form attributes
(4) Controller invokes LoginAction.execute method
(5) Controller forwards processing to appropriate jsp after execute returns ActionForward
v) DynaActionForm
Dynamic ActionForm for use with simple data inputs
<form-bean name="dynamicloginform"
type="org.apache.struts.action.DynaActionForm">
<form-property name="userid" type="java.lang.String" initial="" />
<form-property name="password" type="java.lang.String" initial="" />
</form-bean>
============================================
7) Debugging Struts
(b) Add new properties: add property, get and set methods
(3) Create Action class that utilizes new Attribute in ActionMapping sub class
WroxActionMapping wm = (WroxActionMapping) mapping;
if (wm.getLogResults()) ...
9) Internationalizing Struts (i18n)
a) i18n Components
i) Resource bundle based Message class
ii) <bean:message /> tag
b) Controller
i) java properties file containing key=value pairs
ex: app.symbol=Symbol
EITHER
i) web.xml file
(1) servlet element
(2) <init-param>
(3) ex:
<init-param>
<param-name>application</param-name>
<param-value>ApplicationResources</param-value>
</init-param>
OR
ii) struts-config.xml file
(1) <message-resources element
<message-resources parameter="ch09ApplicationResources" />
i) <bean:message key=”app.symbol”/>
b) ActionErrors
i) ActionErrors errs = new ActionErrors()
ii) errs.add(“some_property_value”, new ActionError(“somekey”));
iii) property value is the property in the input jsp that caused the error
e) ActionForm
i) public ActionErrors validate(ActionMapping mapping, HttpServletRequest request)
return errs;
g) jsp's
i) <html:errors /> tag (pg 166)
(7) As long as
the key used in the ActionError constructor is in the ApplicationResources.properties file
<html:errors /> or is in the input or failure forward jsp
Example Steps
7. Edit the struts-config file and put in validate=”false” in the ch10 action
to
============================================
12) Validator Plugin
Validation of form input while not “required” is good practice, enables reuse, & follows MVC
This chapter shows how to use the Validator Plugin to replace or augment the validate method
---- validator.xml in the text is validation.xml in the blank struts app ----
iv) 4. As you work add keys & labels to the jsp's and resource bundle
Remember the goal is that all static text is removed from the jsp
v) 5. Create an input jsp (login,jsp) using the action form & fields (step 1) above (p184)
be careful using value=”something” attributes in the html:text element.
They will override previous entries in the form
vi) 6. Use keys from resource bundle for all prompts (step 4)
vii) 7. Add form bean declaration to the module (or default) struts config file (p185)
viii) 8. Add Action mapping to the module (or default) struts config file
ix) 9. Create a response page to return as the “success” view
<plug-in className="org.apache.struts.validator.ValidatorPlugIn">
<set-property
property="pathnames"
value="/WEB-INF/ch12/validator-rules.xml, /WEB-INF/ch12/validator.xml" />
</plug-in>
xi) 11. Copy the validator-rules.xml and validation.xml files into WEB-INF
or the module folder under WEB-INF
GOTCHA: be very sure you are using the same versions of your struts.jar & the validator xml files
if you do not you will get strange errors like this:
java.lang.NoSuchMethodException: org.apache.struts.validator.FieldChecks.validateRequired(java.lang.Object,
org.apache.commons.validator.ValidatorAction, org.apache.commons.validator.Field,
org.apache.struts.action.ActionMessages, javax.servlet.http.HttpServletRequest)
xii) 12. Subclass ValidatorForm instead of ActionForm in your form (step 1 above)
public class RegistrationForm extends ValidatorForm {
GOTCHA: if you have a validate method make sure to call super.validate and assign the result to an
ActionErrors object. Only then can you run your own validation logic and add errors to the existing
ActionErrors object.
xiii) 13. Add a form to the form sets in the validation.xml file
Note: When debugging watch the console output in Eclipse.
Small errors like zipcode instead of zipCode will show up easily
Note: regular expressions and the mask rule are very powerful
xiv) 14. Add a field, rules, errors, & error arguments to the form set created in step 13
xv) 15. Add error messages to the resource bundle for all errors created in step 14
Note: use the examples from the top of the validator-rules.xml file as a start
if (!password.equals(passwordChk)) {
errs.add("password", new ActionError("errors.password.mismatch"));
}
return errs;
}
c) Writing Your own rules
i) 1. Create a java class (it can extend anything you wish)
public class ValidatePassword
d) DynaActionForms
use DynaValidatorForm instead of DynaActionForm in the form-bean element
<head>
<title><bean:message key="registration.title" /></title>
<html:javascript formName="registrationform"/>
</head>
jsp:
<html:submit /> <html:cancel onclick=”bCancel=true” />
ActionForm:
if (this.isCancelled(request)) {
sFwd = "home";
}
global-forward:
<forward name=”home” path=”/index.jsp” />
f) Error Logic
<logic:messagesPresent>
<font color='red'>
<strong><bean:message key="errors.header" /></strong>
<ul>
<html:messages id="error">
<li><%= error%></li>
</html:messages> </font>
</ul>
</font>
</logic:messagesPresent>
g) Wizard style Work Flow: or multiple jsp for the same ActionForm / Validate process
i) Benefits:
Allows multiple jsp to access a single form
Allows “Wizard” style input streams
(6) Create two input jsp, use the new form and actions created above
(7) Add a hidden field to the jsp to identify the Action method to use
for example on the first step input jsp:
<html:hidden property="method" value="step1" />
Test it now, if you look at the form data when you are in the second input phase (either debug or
System.err.println) you will notice everything from the first input is gone.
The problem is request scope.
(8) In the action-mappings in the struts-config file, change form to session scope to allow repeated
access
<action path="/regphase2" name="phasedregisterform"
scope="session" input="/reg2.jsp" validate="false"
parameter="method" type="ch12.PhasedRegisterAction">
<forward name="success" path="/Welcome.jsp" />
<forward name="failure" path="/reg2.jsp" />
</action>
(9) Modify validation.xml & make necessary changes to the Form and the Action classes to allow
validation
Following the books naming
(a) Add an additional hidden field for page to each of the input jsp
<html:hidden property="method" value="step1" />
Notice that you can either set the page variable value in the Action as the book
does or as a “static” value in the tag as I do above.
(b) Add a new validation form to the validation.xml file & setup all field validation rules
(c) Add a page=’?’ attribute to each field element indicating where (on which jsp) the field
should be validated
13) Tiles or visual struts components
Goal is reusable presentation components & ability to standardize webapp views
There are several ways to “define” a site layout in my opinion the xml version is best
versus
(b) Use <tiles:getAsString tags to display string parameters such as page title
<title> <tiles:getAsString name="title" ignore="true"/> </title>
(c) Use <tiles:insert tags to insert the tiles into the correct regions of the layout
(d) Use <tiles:put sub tags to pass parameters to tiles being used
<tiles:insert attribute="header" ignore="true">
<tiles:put name="title" beanName="title" beanScope="tile"/>
</tiles:insert>
(3) Create two new content pages that contain only the differences between jsp
(4) Insert the tile layout into the new pages and send parameters to the tiles to customize content
(a) Import the Tiles taglib
(b) Use the <tiles:insert tag to put the layout into the current jsp
(c) Use <tiles:put sub tags to pass parameters (both strings and other tiles)
Example passing just tiles as region components
(d) Build the component pages (footer.jsp, header.jsp, & indexContent.jsp above)
c) creating and using a tile layout definition in a non visual jsp (METHOD 2)
tile definitions add the ability to pass default parameters, this ability helps limit code repetition
<jsp:include page="siteLayoutDefinition.jsp"/>
(6) Use <tiles:insert & <tiles:put tags to override default definitions (index2.jsp)
<tiles:insert beanName="siteLayoutDef" beanScope="application">
<tiles:put name="title" type="string" value="Get Wrox Stock Quote 2" />
<tiles:put name="content" value="indexContent.jsp"/>
</tiles:insert>
d) creating and using a tile layout definition in a non visual XML (METHOD 3)
(1) Add the Tiles plugin for struts to the struts-config file
<tiles-definitions>
</tiles-definitions>.
(3) Replace the beanName and beanScope tags in the previous index2.jsp (index3.jsp)
<tiles:insert definition="siteLayoutDef">
<tiles:put name="title" type="string" value="Get Wrox Stock Quote 3" />
<tiles:put name="content" value="indexContent.jsp"/>
</tiles:insert>
e) Notes:
i) If you are using modules remember to make all the jsp in tile:put tags relative
ii) If you have set the validate xml property in the plugin to true
<set-property property="definitions-parser-validate" value="true" />
Remember to include a link to the dtd in the tiles-defs.xml file
iii)
14) Developing a Complete Struts application
A link to a similar article from The Server Side: Struts Redirect-after-Post
These notes follow the creation of the employees application in PJS: Ch14 as adapted to our system
a) Basic Tomcat / eclipse /MyEclipse / MySql webapp setup
(1) Create a new Project (I followed the book and named mine employees)
(2) Use MyEclipse to add struts capabilities
(I used com.wrox as the base package and employeesResources for the resource file)
(3) Add the mysql jdbc driver jar file to your java build path
(4) Create an English resource bundle (Listing 14.3 pg 247)
(5) Create the /WebRoot/images folder with required images
(6) NOTE: Setting up the tag libraries. In the book the authors always put tag lib defs in the
web.xml file, however when using our environment none are ever found there. The following
note from http://struts.apache.org/userGuide/configuration.html explains why:
Servlet 2.3 users only: The Servlet 2.3 specification simplifies the deployment and configuration of
tag libraries. The instructions above will work on older containers as well as 2.3 containers (Struts
only requires a servlet 2.2 container); however, if you're using a 2.3 container such as Tomcat 4.x,
you can take advantage of a simplified deployment.
All that's required to install the Struts tag libraries is to copy struts.jar into your /WEB-INF/lib
directory and reference the tags in your code like this:
Note that you must use the full uri defined in the various tlds (see the example configuration for
reference) so that the container knows where to find the tag's class files. You don't have to alter your
web.xml file or copy tlds into any application directories.
(2) com.wrox.EmployeeData.java
Provides the webapp --- business model interface
(2) add the index.jsp url to the welcome-file-list element in the web.xml file
Also, note the edit and delete links for each employee
(4) Add the employeeForm form-bean and the the /Add action-mapping to the struts-config file
(4) Add the /Edit & /EditEmployee paths to the action-mappings in the struts-config file
v) delete employee
(1) Create the com.wrox.DeleteEmployeeAction.java
(2) Add the /Delete path to the action-mappings in the struts-config file
The elements must be in exactly this order (they must follow the dtd listed above)
a) XML
i) Elements are delimited by angle brackets and identify the nature of the content they surround.
ii) The element’s content model follows the element name.
iii) ? in the content model indicate optional sub-elements that can occur only once
iv) * in the content model indicate optional sub-elements that may occur zero or more times
v) + indicate optional sub-elements that must occur once but can more times
vi) Attributes are name-value pairs that occur inside start-tags after the element name
vii) % identifies a parameter entry in an element definition
viii)Comments begin with <!-- and end with -->
(1) A CDATA section instructs the parser to ignore most markup characters
<![CDATA[
What ever code
>
Between the start of the section, <![CDATA[ and the end of the section, >, all character data is passed
directly to the application, without interpretation
b) Top-level sub-elements
i) <icon> <small-icon> <large-icon>
<!ELEMENT icon (small-icon?, large-icon?)>
<!ELEMENT small-icon (%Location;)>
<!ELEMENT large-icon (%Location;)>
ii) <display-name>
<!ELEMENT display-name (#PCDATA)>
iii) <description>
<!ELEMENT description (#PCDATA)>
iv) <set-property
<!ELEMENT small-icon (%Location;)>
c) data-sources
<!ELEMENT data-sources (data-source*)>
<!ELEMENT data-source (set-property*)>
<data-sources >
<data-source key="durrett_db_stocks" type="org.apache.commons.dbcp.BasicDataSource">
<set-property property="minCount" value="" />
<set-property property="password" value="guest" />
<set-property property="maxCount" value="" />
<set-property property="username" value="guest" />
<set-property property="driverClassName" value="com.mysql.jdbc.Driver" />
<set-property property="description" value="" />
<set-property property="url" value="jdbc:mysql://129.118.51.8:20/durrett_db" />
<set-property property="readOnly" value="true" />
</data-source>
</data-sources>
i) type – optional DataSource class (default: javax.sql.DataSource) must meet java bean specs
ii) className – optional configuration object must extend org.apche.struts.config.DataSourceConfig
iii) key – unique identifier required if more than one data-source used
d) form-beans
<!ELEMENT form-beans (form-bean*)>
<!ELEMENT form-bean (icon?, display-name?, description?, set-property*, form-property*)>`
<form-beans >
<form-bean name="registrationform" type="ch12.RegistrationForm" />
<form-bean name="sqlform" type="db_sql.SqlForm" />
<form-bean name="phasedregisterform" type="ch12.PhasedRegForm" />
</form-beans>
i) name – unique identifier
ii) type – class name of the form class
e) global-exceptions
<!ELEMENT global-exceptions (exception*)>
<!ELEMENT exception (icon?, display-name?, description?, set-property*)>
<global-exceptions>
<exception key="some.key" type="java.io.IOException" handler="com.yourcorp.ExceptionHandler"/>
</global-exceptions>
ii) You can override exception handlers by defining an exception inside an action
f) global-forwards
<!ELEMENT global-forwards (forward*)>
<!ELEMENT forward (icon?, display-name?, description?, set-property*)>
<global-forwards>
<forward name="home" path="/index.jsp" redirect="false" />
</global-forwards>
i) name: The logical name for this forward. Used in Action’s execute method to forward to the next
appropriate resource.
ii) path: The context relative path to the resource. Example: /index.jsp or /index.do
iii) redirect: True or false. Should ActionServlet redirect to the resource instead of forward? [false]
g) action-mappings
<!ELEMENT action-mappings (action*)>
<!ELEMENT action (icon?, display-name?, description?, set-property*, exception*, forward*)>
<action-mappings >
<action path="/regform" forward="/registration.jsp" />
<action path="/sqlform" forward="/SqlQuery.jsp" />
<action path="/phasedregform" forward="/reg1.jsp" />
</action-mappings>
ii) bufferSize – size (bytes) of the input buffer used for processing file uploads. [4096]
iii) className - Classname of configuration bean. [org.apache.struts.config.ControllerConfig]
iv) contentType - Default content type (and optional character encoding) to be set on each response.
May be overridden by the Action, JSP, or other resource to which the request is forwarded.
[text/html]
v) forwardPattern - Replacement pattern defining how the "path" attribute of a <forward> element is
mapped to a context-relative URL when it starts with a slash (and when the contextRelative property
is false). This value may consist of any combination of the following:
If not specified, the default forwardPattern is consistent with the previous behavior of forwards. [$M$P]
vi) inputForward - Set to true if you want the input attribute of <action> elements to be the name of a
local or global ActionForward, instead of as a module-relative path to the resource to be used as the
input form. [false]
vii) locale - Set to true if you want a Locale object stored in the user's session if not present. [true]
viii) processorClass - The fully qualified Java class name of the RequestProcessor subclass to be used
with this module. [org.apache.struts.chain.ComposableRequestProcessor]
ix) maxFileSize - The maximum size (bytes) of a file to be accepted as a file upload. Can be
expressed as a number followed by a "K", "M", or "G", [250M]
i) message-resources
multiple resource files can be used
<!ELEMENT message-resources (set-property*)>
j) plugins
<!ELEMENT plug-in (set-property*)>
<plug-in className="org.apache.struts.validator.ValidatorPlugIn">
<set-property property="pathnames"
value="/WEB-INF/ch12/validator-rules.xml, /WEB-
INF/ch12/validation.xml" />
</plug-in>
k) Gotcha:
i) Forward vs. redirect: if you set the redirect attribute to true in the forward
you loose the request scope objects (you keep the session scope object of course)
<forward name="success" path="/welcome.do" redirect="true"/>
a) The Problem: you need to create a combo box from database information
for example a set of departments from a dept table as in the chapter 14 employees app
b) The solution
(1) Create java bean class with all the properties necessary for each of your “options”
In my example project (jrd) this is the MenuItem class
(2) Create a collection (a simple array is the easiest) of the beans from your database
In my example I simply “fake it”
GOTCHA: If any item in your collection is null you will get server errors
(3) Save the collection you created in some scope (in my example request)
request.setAttribute("menu", menu);
(4) Create your standard struts jsp – form-bean – action to allow input
(5) On the input jsp add the html:select tag
<html:form action="/DeptChoice">
department :
<html:select property="department" size="1">
<html:options collection="menu" property="value" labelProperty="prompt" />
</html:select>
<html:submit/><html:cancel/>
</html:form>
a) The Problem: you need to create a set of links from database information
for example the main menu in a webapp depends on the role of the person who logs in
b) The solution
(1) – (4) Follow the same pattern as in the html tag example above
(a) id is the object name used in the loop for the collection
(b) name is the collection name in some memory space
(c) scope is where to look for the collection of beans
.
(6) Add the bean:write tags in the logic:iterate element
(a) name is the object name from id in the logic:iterate element
(b) property is the bean property to call with a getSomeProperty query
(c) The rest is normal html
(7)
Addendum
1. Modules
Using modules allows developers to partition a single web application into functional areas. This allows independent
development without struts-config, form, and action coordination problems.
(a)Steps in Using Modules
i. Create a struts-config file for each module
ii.Configure the web.xml deployment descriptor for each module
iii. Co
ii.However when using Tiles and/or Validator this option is more practical
/WEB-INF/moduleA/struts-config.xml
/WEB-INF/moduleB/struts-config.xml
this struture allows seperate placement of the Tiles and Validator config files:
And in Eclipse allows adding forms, etc through the outline (Linux)
/WEB-INF/moduleA/tiles-defs.xml
/WEB-INF/moduleA/validation.xml
/WEB-INF/moduleB/tiles-defs.xml
/WEB-INF/moduleB/validation.xml
i. The typical, single module web.xml file the struts-config file is specified as:
<init-param>
<param-name>config</param-name>
<param-value>/WEB-INF/struts-config.xml</param-value>
</init-param>
ii.When using modules each config parameter must be named to exactly identify the module. The
param-name must be: config/moduleName where moduleName is the exact name you want to use for
your module in this webapplication. For instance, assume you have two modules named ch08 and
ch10:
<init-param>
<param-name>config/ch08</param-name>
<param-value>/WEB-INF/struts-config-ch08.xml</param-value>
</init-param>
<init-param>
<param-name>config/ch10</param-name>
<param-value>/WEB-INF/struts-config-ch10.xml</param-value>
</init-param>
iii. The
module-prefix and is very important. It is used by struts to distinguish and route requests to each
module. The module-prefix becomes part of the URL that is always used to access module jsps,
actions, etc>
All of a module's action paths are relative to the module. For instance, if we have a webapp named
s05_4383 a module named ch08 and an action who's path is /query the URL becomes:
http://someserver:someport/s05_4383/ch08/query
iv. Wh
module name and specified in the web.xml file as simply config, is the default struts-config file and is
used when no module is listed in the URL. Thus files placed in the webapp root or in folders not
named after modules will be controlled through this default config file.
(d)Configure links and actions to access module specific jsps and actions
When using modules you cannot simply link to the relative directory (ch08/index.jsp)
The problem is that the jsp URL will not go through the struts servlet and thus the relative module
configuration will not be loaded and any tag libraries or actions used will be loaded from the default
config file.
To correct this problem all requests for module changing jsps must be routed through the struts servlet.
This is accomplished as follows:
iii. Yo
if you wish to use Tiles or the Validator remember to change the structure per b.ii. Above.
And a “blank” module config file
iii. Op
iv. Cr
Right click on the form-beans element in the outline and chose new Form
You may use the default package or a package name for the form class
Note that the new module is chosen by default
Create the form as you have before do not add the module name to any of the paths
You will end up with a typical form-bean entry and a new ActionForm class
Make the appropriate changes to the class
You should now have an Action class and an action entry in the module struts-config file. Edit the
Action class as you wish to accomplish your action.
vi. Cre
vii. Cre
viii. If y
<global-forwards>
<forward name="localmain" path="/localmain.do"/>
</global-forwards>
<action-mappings>
<action path="/localmain" forward="/index.jsp" />
<action path="/switchMod"type="org.apache.struts.actions.SwitchAction" />
</action-mappings>
and create the index using standard struts links for local module actions and SwitchAction links for
changing to other modules
<html:link action="/switchMod?prefix=&page=/index.jsp">
ix. Ma
Requirements:
1. Java 2 SDK, Standard Edition 1.4 or later installed
2. Eclipse 3.0.x SDK
3. MyEclipse 3.8.3 at least
4. A database server that is supported bythe MyEclipse Database Explorer
5. The MyEclipse Database Explorer configured to browse a sample database
(a)Database Explorer
iii. Rig
iv. Be
(b)ER diagrams
Currently limited to creating diagrams from current databases
iii. No
A. You might have to edit the diagram colors in Preferences
B.MySQL (version 4.1.7) supports foreign keys only in InnoDB tables
C.InnoDB create sql
D. InnoDB insert sql
iv. Inte
A. show engines;
B.show create table SomeTableName;
C.show table status;
D. describe SomeTableName;
E.show tables;
3. User authentication
(a)Authentication
i. Option 1: include a user table in the db schema
A. This option assumes that your db contains a table something like this: (email is the userid)
create table RefUsers (
password varchar(20) NOT NULL, nickname varchar(20) NOT NULL,
email varchar(50) NOT NULL, scope varchar(15) NOT NULL, lastname varchar(30),
firstname varchar(30), bselect boolean default 1, binsert boolean default 0,
bupdate boolean default 0, bdelete boolean default 0,
PRIMARY KEY (email) );
D. The problem here is that if I give the ability to do a generic sql query on the db and the user
does:
select * from RefUsers
They are going to get
E. Leave the create table syntax the same but change the insert statements to:
insert into RefUsers values
(AES_ENCRYPT('Tom','DrJohnisaGreatTeacher!'), "Just Tom", "tom@tom.com", "select", "Tom", "Thompson");
Much less informative. The problem is keeping track of the encryption key
B. Second, insert data into ref_db and users into Ref_User_db and add appropriate users to MySQL
C. Third, either create two data-source elements in your struts-config file or connect to the
Ref_User_db in LogonAction and the ref_db in SqlQueryAction
iii. Optio
possible too.
iv. To s
A. Extend ActionServlet and override the init() method
public class RefActionServlet extends ActionServlet {
H. Change the select statement in the LoginAction to use the new constant