/ Forside / Teknologi / Udvikling / Java / Nyhedsindlæg
Login
Glemt dit kodeord?
Brugernavn

Kodeord


Reklame
Top 10 brugere
Java
#NavnPoint
molokyle 3688
Klaudi 855
strarup 740
Forvirret 660
gøgeungen 500
Teil 373
Stouenberg 360
vnc 360
pmbruun 341
10  mccracken 320
Jakarta struts - fejl ved kompilering
Fra : Preben Holm


Dato : 07-07-05 20:18

Hej gruppe

Jeg er begyndt at læse på struts (i bogen Jakarta Struts Live) som jeg
hentede gratis fra theserverside.com:
http://www.theserverside.com/books/sourcebeat/JakartaStrutsLive/index.tss

Der er et simpelt eksempel som jeg ville prøve at bygge med Ant som
foreskrevet (det første eksempel).

Servlet'en ser således ud:
------------
package strutsTutorial;

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 UserRegistrationAction extends Action {
   public ActionForward execute (ActionMapping mapping,
ActionForm form,
HttpServletRequest request,
HttpServletResponse response)
throws Exception {
      return mapping.findForward("success");
   }

}
-----------------

men ved kompilering får jeg fejl på HttpServletRe*-klasserne om at de
ikke findes..

Jeg har j2sdk og tomcat5 installeret på min gentoo-boks. Jeg har gjort
som foreskrevet i vejledningen..

build.xml:
-----------------
<project name="blank" basedir="../" default="all">


<!-- Local system paths -->
<property name="servlet.jar"
value="/opt/tomcat5/common/lib/servlet-api.jar"/>
<property name="jdbc20ext.jar"
value="/javasoft/lib/jdbc2_0-stdext.jar"/>
<!-- NOTE: If "dist" target is used, a local
"projects/lib" directory will be utilized or created -->
<property name="distpath.project" value="/projects/lib"/>


<!-- Project settings -->
<property name="project.title" value="Jakarta Struts Blank "/>
<property name="project.distname" value="strutsTutorial"/>
<property name="project.version" value="1.1"/>


<!-- Path settings -->
<property name="doc.path" value="./doc/api"/>
<property name="doc.src" value="./src/java"/>


<!-- classpath for Struts 1.1 -->
<path id="compile.classpath">
<pathelement path ="lib/commons-beanutils.jar"/>
<pathelement path ="lib/commons-digester.jar"/>
<pathelement path ="lib/struts.jar"/>
<pathelement path ="classes"/>
<pathelement path ="${classpath}"/>
<pathelement path ="${servlet.jar}"/>
</path>


<!-- Check timestamp on files -->
<target name="prepare">
<tstamp/>
</target>


<!-- Copy any resource or configuration files -->
<target name="resources">
<copy todir="classes" includeEmptyDirs="no">
<fileset dir="src/java">
<patternset>
<include name="**/*.conf"/>
<include name="**/*.properties"/>
<include name="**/*.xml"/>
</patternset>
</fileset>
</copy>
</target>


<!-- Normal build of application -->
<target name="compile" depends="prepare,resources">
<javac srcdir="src" destdir="classes">
<classpath refid="compile.classpath"/>
</javac>
</target>


<!-- Remove classes directory for clean build -->
<target name="clean"
description="Prepare for clean build">
<delete dir="classes"/>
<mkdir dir="classes"/>
</target>


<!-- Build Javadoc documentation -->
<target name="javadoc"
description="Generate JavaDoc API docs">
<delete dir="./doc/api"/>
<mkdir dir="./doc/api"/>
<javadoc sourcepath="./src/java"
destdir="./doc/api"
classpath="${servlet.jar}:${jdbc20ext.jar}"
packagenames="*"
author="true"
private="true"
version="true"
windowtitle="${project.title} API Documentation"
doctitle="&lt;h1&gt;${project.title} Documentation (Version
${project.version})&lt;/h1&gt;"
bottom="Copyright &#169; 2002">
<classpath refid="compile.classpath"/>
</javadoc>
</target>


<!-- Build entire project -->
<target name="project" depends="clean,prepare,compile,javadoc"/>


<!-- Create binary distribution -->
<target name="dist"
description="Create binary distribution">

<mkdir
dir="${distpath.project}"/>
<jar
jarfile="${distpath.project}/${project.distname}.jar"
basedir="./classes"/>
<copy
file="${distpath.project}/${project.distname}.jar"
todir="${distpath.project}"/>

<war
basedir="../"
warfile="${distpath.project}/${project.distname}.war"
webxml="web.xml">
<exclude name="${distpath.project}/${project.distname}.war"/>
</war>

</target>


<!-- Build project and create distribution-->
<target name="all" depends="project,dist"/>

</project>
--------------


struts-config.xml:
------------------
<?xml version="1.0" encoding="ISO-8859-1" ?>

<!DOCTYPE struts-config PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 1.2//EN"
"http://jakarta.apache.org/struts/dtds/struts-config_1_2.dtd">

<!--
This is a blank Struts configuration file with an example
welcome action/page and other commented sample elements.

Tiles and the Struts Validator are configured using the factory
defaults
and are ready-to-use.

NOTE: If you have a generator tool to create the corresponding Java
classes
for you, you could include the details in the "form-bean"
declarations.
Otherwise, you would only define the "form-bean" element itself,
with the
corresponding "name" and "type" attributes, as shown here.
-->


<struts-config>

<!-- ============================================ Data Source
Configuration -->
<!--
<data-sources>
<data-source type="org.apache.commons.dbcp.BasicDataSource">
<set-property
property="driverClassName"
value="org.postgresql.Driver" />
<set-property
property="url"
value="jdbc:postgresql://localhost/mydatabase" />
<set-property
property="username"
value="me" />
<set-property
property="password"
value="test" />
<set-property
property="maxActive"
value="10" />
<set-property
property="maxWait"
value="5000" />
<set-property
property="defaultAutoCommit"
value="false" />
<set-property
property="defaultReadOnly"
value="false" />
<set-property
property="validationQuery"
value="SELECT COUNT(*) FROM market" />
</data-source>
</data-sources>
-->

<!-- ================================================ Form Bean
Definitions -->

<form-beans>
<!-- sample form bean descriptor for an ActionForm
<form-bean
name="inputForm"
type="app.InputForm"/>
end sample -->

<!-- sample form bean descriptor for a DynaActionForm
<form-bean
name="logonForm"
type="org.apache.struts.action.DynaActionForm">
<form-property
name="username"
type="java.lang.String"/>
<form-property
name="password"
type="java.lang.String"/>
</form-bean>
end sample -->
</form-beans>


<!-- ========================================= Global Exception
Definitions -->

<global-exceptions>
<!-- sample exception handler
<exception
key="expired.password"
type="app.ExpiredPasswordException"
path="/changePassword.jsp"/>
end sample -->
</global-exceptions>


<!-- =========================================== Global Forward
Definitions -->

<global-forwards>
<!-- Default forward to "Welcome" action -->
<!-- Demonstrates using index.jsp to forward -->
<forward
name="welcome"
path="/Welcome.do"/>
</global-forwards>


<!-- =========================================== Action Mapping
Definitions -->

<action-mappings>
<!-- Default "Welcome" action -->
<!-- Forwards to Welcome.jsp -->
<action
path="/Welcome"
forward="/pages/Welcome.jsp"/>

   <action path="/userRegistration"
    type="strutsTutorial.UserRegistrationAction">
    <forward name="success" path="/regSuccess.jsp"/>
   </action>

<!-- sample input and input submit actions

<action
path="/Input"
type="org.apache.struts.actions.ForwardAction"
parameter="/pages/Input.jsp"/>

<action
path="/InputSubmit"
type="app.InputAction"
name="inputForm"
scope="request"
validate="true"
input="/pages/Input.jsp"/>

<action
path="/edit*"
type="app.Edit{1}Action"
name="inputForm"
scope="request"
validate="true"
input="/pages/Edit{1}.jsp"/>

end samples -->
</action-mappings>


<!-- ============================================= Controller
Configuration -->

<controller
processorClass="org.apache.struts.tiles.TilesRequestProcessor"/>


<!-- ======================================== Message Resources
Definitions -->

<message-resources parameter="MessageResources" />


<!-- =============================================== Plug Ins
Configuration -->

<!-- ======================================================= Tiles
plugin -->
<!--
This plugin initialize Tiles definition factory. This later can
takes some
    parameters explained here after. The plugin first read parameters from
    web.xml, thenoverload them with parameters defined here. All parameters
    are optional.
The plugin should be declared in each struts-config file.
- definitions-config: (optional)
Specify configuration file names. There can be several comma
       separated file names (default: ?? )
- moduleAware: (optional - struts1.1)
Specify if the Tiles definition factory is module aware. If
true
(default), there will be one factory for each Struts module.
         If false, there will be one common factory for all module. In this
later case, it is still needed to declare one plugin per
module.
The factory will be initialized with parameters found in the
first
initialized plugin (generally the one associated with the
default
module).
          true : One factory per module. (default)
          false : one single shared factory for all modules
    - definitions-parser-validate: (optional)
    Specify if xml parser should validate the Tiles configuration
file.
          true : validate. DTD should be specified in file header (default)
          false : no validation

    Paths found in Tiles definitions are relative to the main context.
-->

<plug-in className="org.apache.struts.tiles.TilesPlugin" >

<!-- Path to XML definition file -->
<set-property property="definitions-config"
value="/WEB-INF/tiles-defs.xml" />
<!-- Set Module-awareness to true -->
<set-property property="moduleAware" value="true" />
</plug-in>


<!-- =================================================== Validator
plugin -->

<plug-in className="org.apache.struts.validator.ValidatorPlugIn">
<set-property
property="pathnames"
value="/WEB-INF/validator-rules.xml,/WEB-INF/validation.xml"/>
</plug-in>

</struts-config>

----------------




web.xml:
----------------
<?xml version="1.0" encoding="ISO-8859-1"?>

<!DOCTYPE web-app
PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.2//EN"
"http://java.sun.com/j2ee/dtds/web-app_2_2.dtd">

<web-app>
<display-name>Struts Blank Application</display-name>

<!-- Standard Action Servlet Configuration (with debugging) -->
<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>debug</param-name>
<param-value>2</param-value>
</init-param>
<init-param>
<param-name>detail</param-name>
<param-value>2</param-value>
</init-param>
<load-on-startup>2</load-on-startup>
</servlet>


<!-- Standard Action Servlet Mapping -->
<servlet-mapping>
<servlet-name>action</servlet-name>
<url-pattern>*.do</url-pattern>
</servlet-mapping>


<!-- The Usual Welcome File List -->
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>


<!-- Struts Tag Library Descriptors -->
<taglib>
<taglib-uri>/tags/struts-bean</taglib-uri>
<taglib-location>/WEB-INF/struts-bean.tld</taglib-location>
</taglib>

<taglib>
<taglib-uri>/tags/struts-html</taglib-uri>
<taglib-location>/WEB-INF/struts-html.tld</taglib-location>
</taglib>

<taglib>
<taglib-uri>/tags/struts-logic</taglib-uri>
<taglib-location>/WEB-INF/struts-logic.tld</taglib-location>
</taglib>

<taglib>
<taglib-uri>/tags/struts-nested</taglib-uri>
<taglib-location>/WEB-INF/struts-nested.tld</taglib-location>
</taglib>

<taglib>
<taglib-uri>/tags/struts-tiles</taglib-uri>
<taglib-location>/WEB-INF/struts-tiles.tld</taglib-location>
</taglib>

</web-app>
----------------





Kan i finde nogle fejl?

Eller hvad gør jeg galt?



Med venlig hilsen
Preben Holm

 
 
Thorbjoern Ravn Ande~ (07-07-2005)
Kommentar
Fra : Thorbjoern Ravn Ande~


Dato : 07-07-05 18:48

Preben Holm <64bitNOSPAMNO@mailme.dk> writes:

> <!-- Local system paths -->
> <property name="servlet.jar"
> value="/opt/tomcat5/common/lib/servlet-api.jar"/>

Er den her rigtig?

--
Thorbjørn Ravn Andersen
http://unixsnedkeren.dk/ravn/

Preben Holm (07-07-2005)
Kommentar
Fra : Preben Holm


Dato : 07-07-05 20:59

Thorbjoern Ravn Andersen wrote:
> Preben Holm <64bitNOSPAMNO@mailme.dk> writes:
>
>
>> <!-- Local system paths -->
>> <property name="servlet.jar"
>>value="/opt/tomcat5/common/lib/servlet-api.jar"/>
>
>
> Er den her rigtig?

Ja, det er den, men har lige opdaget, at den ikke er tilgængelig for
andet end root!
Permissions til /opt/tomcat5 var sat til 700 og ikke 755 som den burde
for at user-gruppen kan læse det.

Måske endda det har en årsag? Hvad siger sikkerhedseksperterne til at
jeg har ændret den permission?


Med venlig hilsen
Preben Holm

Søg
Reklame
Statistik
Spørgsmål : 177438
Tips : 31962
Nyheder : 719565
Indlæg : 6408041
Brugere : 218879

Månedens bedste
Årets bedste
Sidste års bedste