Why is the name of java file is same as public class?

hello friends
why we need to assign same name to .java file as the name of public class in .java file? while its not necessary for the class having no modifier?

This question has been asked several times. Serch the forum.
x

Similar Messages

  • Unable to compile the JAXB generated java files

    Hi
    I am using JAXB 2.0 API for binding process.
    I have products.xml file as
    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE PRODUCTDATA SYSTEM "products.dtd">
    <PRODUCTDATA>
    <PRODUCT PRODID="P001" CATEGORY="Books">
    <PRODUCTNAME>Gone with the wind</PRODUCTNAME>
    <DESCRIPTION>This is abt American Civil War</DESCRIPTION>
    <PRICE>25.00</PRICE>
    <QUANTITY>3</QUANTITY>
    </PRODUCT>
    </PRODUCTDATA>
    and products.xsd(Schema file) as
    <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">
    <xsd:element name="PRODUCTDATA" type="prdt"/>
    <xsd:complexType name="prdt">
    <xsd:sequence>
    <xsd:element name="PRODUCT" type="prd" maxOccurs="unbounded" />
    </xsd:sequence>
    </xsd:complexType>
    <xsd:complexType name="prd">
    <xsd:sequence>
    <xsd:element name="PRODUCTNAME" type="xsd:string"/>
    <xsd:element name="DESCRIPTION" type="xsd:string"/>
    <xsd:element name="PRICE" type="xsd:positiveInteger"/>
    <xsd:element name="QUANTITY" type="xsd:nonNegativeInteger"/>
    </xsd:sequence>
    <xsd:attribute name="PRODID" type="pid" use="required"/>
    <xsd:attribute name="CATEGORY" type="xsd:string" use="optional"/>
    </xsd:complexType>
    <xsd:simpleType name="pid">
    <xsd:restriction base="xsd:string">
    <xsd:pattern value="[p]{1}/d{3}"/>
    <xsd:length value="4"/>
    </xsd:restriction>
    </xsd:simpleType>
    </xsd:schema>
    I am converting these schema file to java files by using binding compiler xjc.
    So that three java files are genearated automatically.
    1) ObjectFactory.java
    // This file was generated by the JavaTM Architecture for XML Binding(JAXB) Reference Implementation, vJAXB 2.0 in JDK 1.6
    // See http://java.sun.com/xml/jaxb
    // Any modifications to this file will be lost upon recompilation of the source schema.
    // Generated on: 2008.06.23 at 04:09:25 PM IST
    package testing.jaxb;
    import javax.xml.bind.JAXBElement;
    import javax.xml.bind.annotation.XmlElementDecl;
    import javax.xml.bind.annotation.XmlRegistry;
    import javax.xml.namespace.QName;
    * This object contains factory methods for each
    * Java content interface and Java element interface
    * generated in the testing.jaxb package.
    * <p>An ObjectFactory allows you to programatically
    * construct new instances of the Java representation
    * for XML content. The Java representation of XML
    * content can consist of schema derived interfaces
    * and classes representing the binding of schema
    * type definitions, element declarations and model
    * groups. Factory methods for each of these are
    * provided in this class.
    @XmlRegistry
    public class ObjectFactory {
    private final static QName PRODUCTDATAQNAME = new QName("", "PRODUCTDATA");
    * Create a new ObjectFactory that can be used to create new instances of schema derived classes for package: testing.jaxb
    public ObjectFactory() {
    * Create an instance of {@link Prd }
    public Prd createPrd() {
    return new Prd();
    * Create an instance of {@link Prdt }
    public Prdt createPrdt() {
    return new Prdt();
    * Create an instance of {@link JAXBElement }{@code <}{@link Prdt }{@code >}}
    @XmlElementDecl(namespace = "", name = "PRODUCTDATA")
    public JAXBElement<Prdt> createPRODUCTDATA(Prdt value) {
    return new JAXBElement<Prdt>(_PRODUCTDATA_QNAME, Prdt.class, null, value);
    2)Prdt.java
    // This file was generated by the JavaTM Architecture for XML Binding(JAXB) Reference Implementation, vJAXB 2.0 in JDK 1.6
    // See http://java.sun.com/xml/jaxb
    // Any modifications to this file will be lost upon recompilation of the source schema.
    // Generated on: 2008.06.23 at 04:09:25 PM IST
    package testing.jaxb;
    import java.util.ArrayList;
    import java.util.List;
    import javax.xml.bind.annotation.XmlAccessType;
    import javax.xml.bind.annotation.XmlAccessorType;
    import javax.xml.bind.annotation.XmlElement;
    import javax.xml.bind.annotation.XmlType;
    * <p>Java class for prdt complex type.
    * <p>The following schema fragment specifies the expected content contained within this class.
    * <pre>
    * <complexType name="prdt">
    * <complexContent>
    * <restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
    * <sequence>
    * <element name="PRODUCT" type="{}prd" maxOccurs="unbounded"/>
    * </sequence>
    * </restriction>
    * </complexContent>
    * </complexType>
    * </pre>
    @XmlAccessorType(XmlAccessType.FIELD)
    @XmlType(name = "prdt", propOrder = {
    "product"
    public class Prdt {
    @XmlElement(name = "PRODUCT", required = true)
    protected List<Prd> product;
    * Gets the value of the product property.
    * <p>
    * This accessor method returns a reference to the live list,
    * not a snapshot. Therefore any modification you make to the
    * returned list will be present inside the JAXB object.
    * This is why there is not a <CODE>set</CODE> method for the product property.
    * <p>
    * For example, to add a new item, do as follows:
    * <pre>
    * getPRODUCT().add(newItem);
    * </pre>
    * <p>
    * Objects of the following type(s) are allowed in the list
    * {@link Prd }
    public List<Prd> getPRODUCT() {
    if (product == null) {
    product = new ArrayList<Prd>();
    return this.product;
    3) Prd.java
    // This file was generated by the JavaTM Architecture for XML Binding(JAXB) Reference Implementation, vJAXB 2.0 in JDK 1.6
    // See http://java.sun.com/xml/jaxb
    // Any modifications to this file will be lost upon recompilation of the source schema.
    // Generated on: 2008.06.23 at 04:09:25 PM IST
    package testing.jaxb;
    import java.math.BigInteger;
    import javax.xml.bind.annotation.XmlAccessType;
    import javax.xml.bind.annotation.XmlAccessorType;
    import javax.xml.bind.annotation.XmlAttribute;
    import javax.xml.bind.annotation.XmlElement;
    import javax.xml.bind.annotation.XmlType;
    * <p>Java class for prd complex type.
    * <p>The following schema fragment specifies the expected content contained within this class.
    * <pre>
    * <complexType name="prd">
    * <complexContent>
    * <restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
    * <sequence>
    * <element name="PRODUCTNAME" type="{http://www.w3.org/2001/XMLSchema}string"/>
    * <element name="DESCRIPTION" type="{http://www.w3.org/2001/XMLSchema}string"/>
    * <element name="PRICE" type="{http://www.w3.org/2001/XMLSchema}positiveInteger"/>
    * <element name="QUANTITY" type="{http://www.w3.org/2001/XMLSchema}nonNegativeInteger"/>
    * </sequence>
    * <attribute name="CATEGORY" type="{http://www.w3.org/2001/XMLSchema}string" />
    * <attribute name="PRODID" use="required" type="{}pid" />
    * </restriction>
    * </complexContent>
    * </complexType>
    * </pre>
    @XmlAccessorType(XmlAccessType.FIELD)
    @XmlType(name = "prd", propOrder = {
    "productname",
    "description",
    "price",
    "quantity"
    public class Prd {
    @XmlElement(name = "PRODUCTNAME", required = true)
    protected String productname;
    @XmlElement(name = "DESCRIPTION", required = true)
    protected String description;
    @XmlElement(name = "PRICE", required = true)
    protected BigInteger price;
    @XmlElement(name = "QUANTITY", required = true)
    protected BigInteger quantity;
    @XmlAttribute(name = "CATEGORY")
    protected String category;
    @XmlAttribute(name = "PRODID", required = true)
    protected String prodid;
    * Gets the value of the productname property.
    * @return
    * possible object is
    * {@link String }
    public String getPRODUCTNAME() {
    return productname;
    * Sets the value of the productname property.
    * @param value
    * allowed object is
    * {@link String }
    public void setPRODUCTNAME(String value) {
    this.productname = value;
    * Gets the value of the description property.
    * @return
    * possible object is
    * {@link String }
    public String getDESCRIPTION() {
    return description;
    * Sets the value of the description property.
    * @param value
    * allowed object is
    * {@link String }
    public void setDESCRIPTION(String value) {
    this.description = value;
    * Gets the value of the price property.
    * @return
    * possible object is
    * {@link BigInteger }
    public BigInteger getPRICE() {
    return price;
    * Sets the value of the price property.
    * @param value
    * allowed object is
    * {@link BigInteger }
    public void setPRICE(BigInteger value) {
    this.price = value;
    * Gets the value of the quantity property.
    * @return
    * possible object is
    * {@link BigInteger }
    public BigInteger getQUANTITY() {
    return quantity;
    * Sets the value of the quantity property.
    * @param value
    * allowed object is
    * {@link BigInteger }
    public void setQUANTITY(BigInteger value) {
    this.quantity = value;
    * Gets the value of the category property.
    * @return
    * possible object is
    * {@link String }
    public String getCATEGORY() {
    return category;
    * Sets the value of the category property.
    * @param value
    * allowed object is
    * {@link String }
    public void setCATEGORY(String value) {
    this.category = value;
    * Gets the value of the prodid property.
    * @return
    * possible object is
    * {@link String }
    public String getPRODID() {
    return prodid;
    * Sets the value of the prodid property.
    * @param value
    * allowed object is
    * {@link String }
    public void setPRODID(String value) {
    this.prodid = value;
    Next step is to compile these three files
    So I am compiling these three files it gives me compiler error as:
    testing/jaxb/ObjectFactory.java:31: illegal character: \64
    @XmlRegistry
    ^
    testing/jaxb/ObjectFactory.java:63: illegal character: \64
    @XmlElementDecl(namespace = "", name = "PRODUCTDATA")
    ^
    testing/jaxb/ObjectFactory.java:65: <identifier> expected
    return new JAXBElement<Prdt>(_PRODUCTDATA_QNAME, Prdt.class, null, value
    ^
    testing/jaxb/ObjectFactory.java:65: <identifier> expected
    return new JAXBElement<Prdt>(_PRODUCTDATA_QNAME, Prdt.class, null, value
    ^
    testing/jaxb/ObjectFactory.java:65: '{' expected
    return new JAXBElement<Prdt>(_PRODUCTDATA_QNAME, Prdt.class, null, value
    ^
    testing/jaxb/Prdt.java:38: illegal character: \64
    @XmlAccessorType(XmlAccessType.FIELD)
    ^
    testing/jaxb/Prdt.java:39: illegal character: \64
    @XmlType(name = "prdt", propOrder = {
    ^
    testing/jaxb/Prdt.java:44: illegal character: \64
    @XmlElement(name = "PRODUCT", required = true)
    ^
    testing/jaxb/Prdt.java:45: <identifier> expected
    protected List<Prd> product;
    ^
    testing/jaxb/Prdt.java:69: <identifier> expected
    public List<Prd> getPRODUCT() {
    ^
    testing/jaxb/Prdt.java:75: ';' expected
    ^
    testing/jaxb/Prd.java:43: illegal character: \64
    @XmlAccessorType(XmlAccessType.FIELD)
    ^
    testing/jaxb/Prd.java:44: illegal character: \64
    @XmlType(name = "prd", propOrder = {
    ^
    testing/jaxb/Prd.java:52: illegal character: \64
    @XmlElement(name = "PRODUCTNAME", required = true)
    ^
    testing/jaxb/Prd.java:53: <identifier> expected
    protected String productname;
    ^
    testing/jaxb/Prd.java:54: illegal character: \64
    @XmlElement(name = "DESCRIPTION", required = true)
    ^
    testing/jaxb/Prd.java:55: <identifier> expected
    protected String description;
    ^
    testing/jaxb/Prd.java:56: illegal character: \64
    @XmlElement(name = "PRICE", required = true)
    ^
    testing/jaxb/Prd.java:57: <identifier> expected
    protected BigInteger price;
    ^
    testing/jaxb/Prd.java:58: illegal character: \64
    @XmlElement(name = "QUANTITY", required = true)
    ^
    testing/jaxb/Prd.java:59: <identifier> expected
    protected BigInteger quantity;
    ^
    testing/jaxb/Prd.java:60: illegal character: \64
    @XmlAttribute(name = "CATEGORY")
    ^
    testing/jaxb/Prd.java:61: <identifier> expected
    protected String category;
    ^
    testing/jaxb/Prd.java:62: illegal character: \64
    @XmlAttribute(name = "PRODID", required = true)
    ^
    testing/jaxb/Prd.java:63: <identifier> expected
    protected String prodid;
    ^
    25 errors
    I want all three files to compiled successfully.If it is compiled only then I will continue on Unmarshalling process

    I suspect you are trying to compile the files one by one. You may also be trying to compile them disregarding the package structure.
    From your post, I gather these files are in the package: com.geindustrial.sqms
    Therefore, if they are not so already, put them under a directory structure:
    com/geindustrial/sqms
    and then compile with:
    javac com/geindustrial/sqms/AddCtq.java com/geindustrial/sqms/Ctq.java com/geindustrial/sqms/VariableData.java
    (The above is all on one line.)
    HTH,
    Manuel Amago.

  • Can we get the name of fmx file at runtime

    Hi all,
    can we get the name of fmx file which is doing some DML operation on a specific table Can we back track which fmx module has done DML on a specific table. The reason I need this because I've 7 different fmx files which are doing some DML operation on a specific table and these fmx files were used by different users. Not necessarily 1:1 For eg. one user can do DML through 3 different fmx files. So in such case if I want to want to know from which fmx file this DML has take place .How can I achieve that. I know I can get the oracle username through v$session but it will not suffice my needs. I need the name of fmx file also.
    I'm using:
    Forms [32 Bit] Version 10.1.2.0.2 (Production)
    Oracle Database 10g Release 10.2.0.1.0 - Production
    PL/SQL Release 10.2.0.1.0 - Production
    CORE    10.2.0.1.0      Production
    TNS for 32-bit Windows: Version 10.2.0.1.0 - Production
    NLSRTL Version 10.2.0.1.0 - Production
    Any help?
    Warm Regards
    Percy

    Percy,
    For that you can set the Module Field in the V$session in each form by,
    DBMS_APPLICATION_INFO.SET_MODULE(MODULE_NAME => :SYSTEM.CURRENT_FORM, ACTION_NAME => USER);Write this in each form, and then you will get the form name in the V$SESSION's module field with form name.
    Hope this helps.
    Regards,
    Manu.

  • Change the name of a file.

    Hello, I don't how can I change the name of a file ?.
    Somebody can help me, please?
    For example : c:\out\prove1.csv to  c:\out\prove1_09112007_163001.csv
    Thanks

    Another way would be to use the FILE_COPY and
    FILE_DELETE of the class CL_GUI_FRONTEND_SERVICES to first copy the file and then delete the other one.
    REgards,
    Rich Heilman

  • BEx Brodcaster for Workbook - Cannot change the name of attachment file.

    Dear All Experts,
    I am using the BEx Broadcaster to distribute report of workbook via email. The name of attchament file in email is the technical of workbook. I want change the name of attchment file and found this thread
    [Broadcasting Workbook - Change attachment filename|Broadcasting Workbook - Change attachment filename] that reference to method in background process. Can I create customize program or method to change the name of file.
    Thank you and really appreciate your help.
    Zilla D.

    Hello Zilla,
    By SAP methods, this is not possible. There is no way to do that. May you can suggest it on our Community of Innovation. See note 11.
    This is not only your concern. Some customers already request this functionallity.
    Best Regards,
    Edward John

  • Why does the folder "C:\Program Files\Adobe\Elements" open automatically when I start my PC?

    Why does the folder "C:\Program Files\Adobe\Elements" open automatically when I start my PC? How do I adjust settings to stop this from happening?

    Hi,
    This folder is probably treated as a program to run at startup.
    So you will have to look at the places where such programs are referenced.
    For instance, you may have a shortcut to that folder in your Start Menu > Startup.
    Or it may be in the Registry.
    Click on Start >  Execute, the type msconfig and click OK.
    This will show you in the Startup tab all the programs launched at startup.
    Astugev

  • How to keep HTML code in the applet source (.java) file itself?

    Hi,
    How to keep HTML code (APPLET tag) in the applet source (.java) file itself?
    Please give an example?
    thank you,

    R6i wrote:
    ...What I mean is without writing external HTML file, how to run an applet (during practice)?'Practice'? What does that mean? During development? If that is what you are referring to, add an applet tag at the top of YourApplet.java inside a Java comment area. Then AppletViewer (in recent SDKs) can then run it with just..
    prompt:javac YourApplet.java
    prompt:// the '.java' extension is not a mistake
    prompt:appletviewer YourApplet.javaIf you do not mean 'during development', then that brings us back to +"What advantages do you see that is bringing to the end user?".+

  • Why does the name change to my dad's name when I use his credit card for downloads?

    I have an iPod touch. I have my own apple ID and icloud account. Why does the name change to my dad's name when I use his credit card for downloads? Is there a way I can have my own account and use my dad's card without having his name on my photostream and icloud?
    I went on icloud.com and changed my name but it changes the credit card name to mine as well so I can't get apps unless its under his name, but it confuses everyone i share photo streams with, as there are two of my dads?
    My aunt is having the same problem with her photostream, so I know its not only me.

    I have this problem and it's annoying.  Plenty of people in this world do not pay for their own stuff!.  So i have 5 kids.  All there accounts show as my name when people add them for Photo streams etc etc.  This is ridiculous.  Why not seperate billing address / credit card details to the name of the person on the account?  Why do they have to be the same?

  • When I click on the Start Icon and type the name of a file I am searching for none appear.

    When I click on the Start Icon and type the name of a file I am searching for none appear.
    Using Widows 7

    Are you searching for a file that you downloaded via Firefox?
    If that is the case then you can check the Download Manager (Tools > Downloads) and if that file is listed there then right click that entry and choose > Open Containing Folder. If that entry is grayed then the file is no longer in the original download location and possibly removed by AV software.

  • Why does an outline and the name of a file stay in Microsoft Word after I delete the actual document? How do I get rid of this?

    I was told to post this question on the Microsoft Word for Mac forum, but I have no idea how to get to that. After I delete a file, I can no longer access it, but the name and a dotted line outline (but not a picture of the actual document) remain. I want this gone, as it is fairly annoying to be able to see 100+ documents that should no longer exist on my computer. It is cluttered, and someone mentioned that it might have something to do with a setting in microsoft for the number of documents displayed, or something along those lines. If anyone can tell me how to PERMANENTLY get rid of these documents, I would greatly appreciate it.

    Google "Microsoft Word for Mac forum". This is what comes up.
    https://www.google.com/search?q=Microsoft+Wrod+for+Mac+forum&oq=Microsoft+Wrod+f or+Mac+forum&aqs=chrome..69i57.9776j0&sourceid=chrome&ie=UTF-8
    Which includes this link
    http://www.microsoft.com/mac/support
    Which has a link to the forums.
    http://answers.microsoft.com/en-us/mac?auth=1

  • Controling the 'name' of a file download

    function openPDFWordTwo(thisObj,pdfURL){
    //For Opening Word
    formTitleId = thisObj.id.substr(0,thisObj.id.lastIndexOf(':')) + ":hiddenFormTitle";
    formTitle = document.getElementById(formTitleId).value;
    window.location = pdfURL;
       return false;Here is my code that opens the popup window for my page to download a word document by JavaScript. Right now it downloads the correct file but names it servername.doc. I would like to change it to formTitle.doc. Is there a way I could do that through code or is it server style?
    I was looking at HTTP responses but I haven't figured out exactly how they work yet. Any good tutorials?
    Cheers

    I realize this, I googled read about it but all the examples I have found completely redo the process, html uploading the file etc. I have no idea what you're talking about. HTML is just a markup language. With regard to file uploading it only provides you a <form> and a <input type="file"> to represent a file chooser and with regard to file downloading it only provides you an <a> element to represent a download link or a <form> and <button> element to represent a download button. It has completely no capabilities to process a file upload or download. It is the server side code which does that, Java/JSP/Servlet for example.
    My question was if there is a way to keep my html keep the way the file is accessed and changing the name.My answer was under each: if you want to try this with JavaScript, please realize that JavaScript != Java. With other words, you're here at a Java forum at the wrong place. At any way, I don't see why you insist to do this in JavaScript. It's a client side scripting language.

  • How do you find out the name of a file in a specific folder

    The problem I have is that I want to read from a file located on the harddrive. I know where it is located and that it is the last updated folder, but not the name of it.
    The reason for why I want the name is that I want to read som values from that specific file.
    Hope for fast answer.
    //Emelia

    Check out the File.list() and File.lastModified() methods:
    http://java.sun.com/j2se/1.4.2/docs/api/java/io/File.html

  • How to create a record based on the name of a file in the file-system?

    Hi,
    With a lot of pictures I want to have a database to gather some information about these pictures.
    First question is how to generate a record based on a file in the file system?
    e.g. the pictures are "c:\fotos\2009\01\disc_001.jpg" to "c:\foto\2009\01\dis_98.jpg" .
    now i want to create records with as one of the attributes the name of the picture (not the picture itself). how to create these records (based on the information of the file-ssytem). i.e. the number of records should be the same as the number of pictures.
    any suggestions?
    any reaction will be appreciated.
    Leo

    Link to Create directory
    http://www.adp-gmbh.ch/ora/sql/create_directory.html
    You can create a list of files in the directory and read the list files from that directory.
    [UTL_FILE Documentation |http://download.oracle.com/docs/cd/B14117_01/appdev.101/b10802/u_file.htm#996728]
    [Solution using Java|http://asktom.oracle.com/pls/asktom/f?p=100:11:0::::P11_QUESTION_ID:439619916584]
    SS

  • Trying to change the name of 1 file

    I have searched the topic and have not found a solution that works for me,
    I am trying to write an AppleScript that will change the name of a single file from path:old.txt to path:new.txt
    I have tried
    tell application "Finder"
    set name of file "work.txt" to PartA & PartG & ticker & ".txt"
    end tell
    among others and always either receive an error message, access denied or unable to set old file name to new file name

    You're missing the point.
    set name of file "work.txt" to PartA & PartG & ticker & ".txt"
    When you set the name of the file, the Finder needs two things - the original file that you're trying to rename, and the new name you want it to take.
    In your revised script you're specifying the existing name (not path) of the file you want to change, and specifying its path along with the new name. That's the wrong way around.
    Think of this command in the following manner:
    set name of (original file specification) to (new file name)
    Now, in the case of the 'original file specification' you need to provide enough information for the Finder to identify the file. You're just saying 'work.txt', but that is not enough (and that's why it's complaining). There could be a hundred 'work.txt' files spread around in different directories on your disk. How is the Finder supposed to know which one you want to change?
    A better format would be:
    tell application "Finder"
      set name of (file "work.txt" of path to desktop) to "ABC.txt"
    end tell
    In this way the Finder can absolutely identify which file you want to change (the file 'work.txt' that's on your desktop) and the new name you want it to take.
    Now, if the file is not on your desktop you can amend the script to include the relevant path, e.g.:
    tell application "Finder"
      set name of (file "work.txt" of folder "blah" of disk "disk name") to "ABC.txt"
    end tell
    This tells the Finder to look in the folder 'blah' on the specified disk.
    You can also do this by including the path to the file in the form:
    tell application "Finder"
      set name of (file "disk name:blah:work.txt) to "ABC.txt"
    end tell
    where you use : to delimit each folder in the path.
    Hope that helps.

  • Trying to Validate the name of a file with a Validator

    Hi, Im trying to validate an file name that is sent with a form
    I want that the Validator Checks if the filename ends with some extensions (.jpg ,etcc) for only addmit one type of files (images)
    I ve build my own Pluggable Validator , but I dont know how to extract the filename from Validator.
    Can anyone help me??
    the Code is something like this
    where
    package jmar5439.webpage.validator;
    import javax.servlet.ServletContext;
    import javax.servlet.http.HttpServletRequest;
    import java.io.Serializable;
    import org.apache.struts.action.*;
    import org.apache.commons.validator.ValidatorAction;
    import org.apache.commons.validator.*;
    import org.apache.commons.validator.Field;
    import org.apache.commons.validator.GenericValidator;
    import org.apache.commons.validator.util.ValidatorUtils;
    import org.apache.commons.validator.Validator;
    import org.apache.struts.validator.Resources;
    import org.apache.commons.logging.LogFactory;
    import jmar5439.webpage.action.InsertRoomAction;
    import org.apache.commons.logging.Log;
    public class ImageFileValidator implements Serializable {
    // public ImageFileValidator() {}
    public static boolean validateImageFile(Object bean, ValidatorAction va,
    Field field, ActionMessages errors,
    HttpServletRequest request, Validator validator) {
    String value = null;
    if (field.getProperty() != null && field.getProperty().length() > 0) {
    value = ValidatorUtils.getValueAsString(bean, field.getProperty());
    String file = new String(value);
    file = file.toLowerCase();
    if (!GenericValidator.isBlankOrNull(value)) {
    try {
    if (!file.endsWith(".jpeg") || !file.endsWith(".gif") ||
    !file.endsWith(".jpg")) {
    errors.add(field.getKey(),
    Resources.getActionMessage(request, va,
    field));
    return false;
    } catch (Exception e) {
    errors.add(field.getKey(),Resources.getActionMessage(request, va,field));
    return false;
    return false;
    return false;
    I ve declared
    <form-property name="file"
                   type="org.apache.struts.upload.FormFile"/>
    in struts-config file and
    <field property="file"
                        depends="imagefile">
    in validate file.
    Thanks

    I ve solved like this
    package jmar5439.webpage.validator;
    import javax.servlet.ServletContext;
    import javax.servlet.http.HttpServletRequest;
    import java.io.Serializable;
    import org.apache.struts.action.*;
    import org.apache.commons.validator.ValidatorAction;
    import org.apache.commons.validator.*;
    import org.apache.commons.validator.Field;
    import org.apache.commons.validator.GenericValidator;
    import org.apache.commons.validator.util.ValidatorUtils;
    import org.apache.commons.validator.Validator;
    import org.apache.struts.validator.Resources;
    import org.apache.commons.logging.LogFactory;
    import jmar5439.webpage.action.InsertRoomAction;
    import org.apache.commons.logging.Log;
    import org.apache.struts.upload.FormFile;
    import org.apache.commons.beanutils.PropertyUtils;
    import java.lang.reflect.*;
    public class ImageFileValidator implements Serializable {
    // public ImageFileValidator() {}
    public static boolean validateImageFile(Object bean, ValidatorAction va,
    Field field, ActionMessages errors,
    Validator validator,
    HttpServletRequest request) {
    Log log = LogFactory.getLog(ImageFileValidator.class);
    //log.info(form.toString() );
    String value = ValidatorUtils.getValueAsString(
    bean,
    field.getProperty());
    if (!GenericValidator.isBlankOrNull(value)) {
    try {
    FormFile file = (FormFile) PropertyUtils.getSimpleProperty(bean,
    "file");
    String filename=file.getFileName().toLowerCase() ;
    //log.info("Filename:" + file.getFileName());
    if (filename.endsWith(".jpeg") ||
    filename.endsWith(".jpg") ||
    filename.endsWith(".gif")) {
    log.info("return true");
    return true;
    } else {
    errors.add(field.getKey(),
    Resources.getActionMessage(request, va,
    field));
    log.info("return false");
    return false;
    } catch (NoSuchMethodException ex) {
    errors.add(field.getKey(),
    Resources.getActionMessage(request, va,
    field));
    return false;
    } catch (InvocationTargetException ex) {
    errors.add(field.getKey(),
    Resources.getActionMessage(request, va,
    field));
    return false;
    } catch (IllegalAccessException ex) {
    errors.add(field.getKey(),
    Resources.getActionMessage(request, va,
    field));
    return false;
    //return false;
    // log.info("Entra0");
    /* if (field.getProperty() != null && field.getProperty().length() > 0) {
    // log.info("Entra");
    // value = ValidatorUtils.getValueAsString(bean, field.getProperty());
    value = ValidatorUtils.getValueAsString(bean, field.getProperty());
    String file = new String(value);
    file = file.toLowerCase();
    if (!GenericValidator.isBlankOrNull(value)) {
    // log.info("Entra2");
    try {
    if (!file.endsWith(".jpeg") || !file.endsWith(".gif") ||
    !file.endsWith(".jpg")) {
    errors.add(field.getKey(),
    Resources.getActionMessage(request, va,
    field));
    //log.info("Entra3");
    return false;
    } catch (Exception e) {
    errors.add(field.getKey(),Resources.getActionMessage(request, va,field));
    return false;
    return false;
    // return true;
    } else {
    return false;
    Remember to visit
    http://www.lloguerjove.com
    and
    http://www.alquilerjoven.com

Maybe you are looking for