1 java file can trigger one of 2 servlets?

I have a form and a servlet that processes it.
but now i have to have the form do something else if the user picks a certain radio button.
I thought of having an If statement that would check if the radio button was checked. If it was, I need another servlet to run.
I now have the new servlet in a separate .java file, and the old servlet in another .java file.
Is there a way to combine these 2 servlets in one .java file?
If not, is there a way for the If statement to trigger the new servlet from the original .java file?
THANKS!!!

Your form post can go to a "router" servlet, which will call request.getParameter("radiobuttons"), and then figure out which servlet to forward the response to from there.
If you are using JSP pages, you can just make your POST go to itself, and then at the top of the page have code such as:
<%
if (request.getMethod().equals("POST")) {
String strRadio = request.getParameter("radiobuttons");
if (strRadio.equals("option1"))
... forward to servlet 1
else
... forward to servlet 2
%>

Similar Messages

  • [svn:bz-trunk] 10059: update two package-info.java files, and add one new one.

    Revision: 10059
    Author:   [email protected]
    Date:     2009-09-08 11:31:48 -0700 (Tue, 08 Sep 2009)
    Log Message:
    update two package-info.java files, and add one new one.
    Modified Paths:
        blazeds/trunk/modules/proxy/src/flex/messaging/services/http/proxy/package-info.java
    Added Paths:
        blazeds/trunk/modules/core/src/flex/messaging/util/concurrent/package-info.java
        blazeds/trunk/modules/core/src/flex/messaging/validators/package-info.java

    Revision: 10059
    Author:   [email protected]
    Date:     2009-09-08 11:31:48 -0700 (Tue, 08 Sep 2009)
    Log Message:
    update two package-info.java files, and add one new one.
    Modified Paths:
        blazeds/trunk/modules/proxy/src/flex/messaging/services/http/proxy/package-info.java
    Added Paths:
        blazeds/trunk/modules/core/src/flex/messaging/util/concurrent/package-info.java
        blazeds/trunk/modules/core/src/flex/messaging/validators/package-info.java

  • Why a single .java file can't have multiple public classes defined in it?

    A public class must be saved in a .java file with the same name, why?

    Tejaswi.Khijwania wrote:
    A public class must be saved in a .java file with the same name, why?This is what the JLS states (7.6 Top Level Type Declarations),
    When packages are stored in a file system (7.2.1), the host system may choose to enforce the restriction that it is a compile-time error if a type is not found in a file under a name composed of the type name plus an extension (such as .java or .jav) if either of the following is true:
    * The type is referred to by code in other compilation units of the package in which the type is declared.
    * The type is declared public (and therefore is potentially accessible from code in other packages).
    This restriction implies that there must be at most one such type per compilation unit. This restriction makes it easy for a compiler for the Java programming language or an implementation of the Java virtual machine to find a named class within a package; for example, the source code for a public type wet.sprocket.Toad would be found in a file Toad.java in the directory wet/sprocket, and the corresponding object code would be found in the file Toad.class in the same directory.
    As you can see a host system (development system) may enforce this restriction. It doesn't have to.

  • I cant open some applications like preview or text edid after installing mavericks, im missing the Base.lproj files, can some one help?

    I cant open some applications like preview or text edit after installing mavericks, i found a post that said im missing the Base.lproj files, this fixed my calendar application but i need the file for preview, can some one help?

    Hi vampyro33,
    Thanks for visiting Apple Support Communities.
    If it seems like system files are missing and applications are quitting unexpectedly, I'd suggest reinstalling Mavericks:
    OS X Mavericks: Reinstall OS X
    http://support.apple.com/kb/PH13871
    Best Regards,
    Jeremy

  • How many number of lines of code Java File can have?

    Hi ALL
    Is there any limit on java source file code length?
    does more code (say more than 4000 line) impact on performace?
    Is there any recomendation on code length and file size?
    Thanks

    Hi ALL
    Is there any limit on java source file code length? There are some (VM) limitations but I have only hit that one when I had some generated code.
    does more code (say more than 4000 line) impact on
    performace?No, but you probably have a stupid design if you have 4000 lines in one file.
    Is there any recomendation on code length and file
    size?You should usually only have one top level clas per file, and you should try to have less than 1000 lines in one class.
    Kaj

  • Hi i am unable to send mail from yahoo mail id.can any one help on this?

    import javax.mail.*;
    import javax.mail.internet.*;
    import javax.activation.*;
    import java.io.*;
    import java.util.Properties;
    public class MailClient
      public void sendMail(String mailServer, String from, String to,
                                 String subject, String messageBody,
                                 String[] attachments) throws
    MessagingException, AddressException
             // Setup mail server
             Properties props = System.getProperties();
             props.put("mail.smtp.host", mailServer);
             // Get a mail session
             Session session = Session.getDefaultInstance(props, null);
             // Define a new mail message
             Message message = new MimeMessage(session);
             message.setFrom(new InternetAddress(from));
             message.addRecipient(Message.RecipientType.TO, new InternetAddress(to));
             message.setSubject(subject);
             // Create a message part to represent the body text
             BodyPart messageBodyPart = new MimeBodyPart();
             messageBodyPart.setText(messageBody);
             //use a MimeMultipart as we need to handle the file attachments
             Multipart multipart = new MimeMultipart();
             //add the message body to the mime message
             multipart.addBodyPart(messageBodyPart);
             // add any file attachments to the message
             addAtachments(attachments, multipart);
             // Put all message parts in the message
             message.setContent(multipart);
             // Send the message
             Transport.send(message);
         protected void addAtachments(String[] attachments, Multipart multipart)
                         throws MessagingException, AddressException
             for(int i = 0; i<= attachments.length -1; i++)
                 String filename = attachments;
    MimeBodyPart attachmentBodyPart = new MimeBodyPart();
    //use a JAF FileDataSource as it does MIME type detection
    DataSource source = new FileDataSource(filename);
    attachmentBodyPart.setDataHandler(new DataHandler(source));
    //assume that the filename you want to send is the same as the
    //actual file name - could alter this to remove the file path
    attachmentBodyPart.setFileName(filename);
    //add the attachment
    multipart.addBodyPart(attachmentBodyPart);
    public static void main(String[] args)
    try
    MailClient client = new MailClient();
    String server="pop3.yahoo.com";
    String from="[email protected]";
    String to = "[email protected]";
    String subject="Test";
    String message="Testing";
    String[] filenames = {"c:\\gopi.txt"};
    client.sendMail(server,from,to,subject,message,filenames);
    catch(Exception e)
    e.printStackTrace(System.out);     
    while compliling this one its compiled succesfully but i am getting exception at run time like..D:\mail>java MailClient
    Exception in thread "main" java.lang.NoClassDefFoundError: com/sun/activation/re
    gistries/MailcapFile
    at javax.activation.MailcapCommandMap.loadFile(MailcapCommandMap.java:275)
    at javax.activation.MailcapCommandMap.<init>(MailcapCommandMap.java:128)
    at javax.activation.CommandMap.getDefaultCommandMap(CommandMap.java:44)
    at javax.activation.DataHandler.getCommandMap(DataHandler.java:136)
    at javax.activation.DataHandler.getDataContentHandler(DataHandler.java:568)
    at javax.activation.DataHandler.getContent(DataHandler.java:501)
    at javax.mail.internet.MimeBodyPart.updateHeaders(MimeBodyPart.java:1253)
    at javax.mail.internet.MimeMessage.updateHeaders(MimeMessage.java:2012)
    at javax.mail.internet.MimeMessage.saveChanges(MimeMessage.java:1980)
    at javax.mail.Transport.send(Transport.java:97)
    at MailClient.sendMail(MailClient.java:35)
    at MailClient.main(MailClient.java:72)
    can any one help on this....plz
    thanks in advance
    Edited by: Konapalli.Gopi on May 20, 2010 5:42 PM                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

    Something's wrong with your CLASSPATH.
    If you're not using JDK 6, you need to include activation.jar in your CLASSPATH.
    If you've got any other jar files that define the javax.mail.* or javax.activation.* classes
    in your CLASSPATH (such as javaee.jar or j2ee.jar), remove them.

  • How to create a .java file through a j2me program?

    I am trying to develop a small application in j2me which needs dynamic creation of a .class file. For this purpose I tried to create .java file through my j2me code, but i could not do that..I want to know whether a java file can be created on a mobile phone or not..
    I would be grateful to you on your help in this regard..

    ...develop a program xyz.java using j2me which performs the following functionalities:
    1.create a file called abc.java
    2.extract its class file...For +1+ ie to create a file (any file, no matter java or not) from j2me, device need to support File Connection specified in [jsr 75|http://www.jcp.org/en/jsr/detail?id=75]. If you're interested, learn the jsr API on how to create and manage needed file.
    For +2+ described as extract its class file one needs to have java compiler (javac) on device. *) If you're interested, ask for more details at [Java Compiler forum|http://forums.sun.com/forum.jspa?forumID=7]. Also, if the class file is for CLDC then javac needs to support "JDK 1.3-compliant" compilation. To create CLDC classes on device, one also needs to have a preverifier tool. Check this at Java Compiler forum if needed.
    Good luck - I think you'll need a lot of it...
    *) javac on device -- it should not only be present but also provide a j2me API allowing to invoke it for particular java file with needed options. Same applies to preverifier tool.

  • Connecting more than java file in an applet game

    I'm creating an applet game that consists of more than one java file, how can I connect those java files in one main program?....And also, how can I hide the first window of my applet and show the next window of my applet from the different java file?
    Can anyone give me a simple code that consists of 2 java files connected in one program and that can hide the first window when I click a button there and opens the next window....please help me with this....thanks....

    Components and windows in java have setVisible(boolean) methods. You can hide them by calling setVisible(false). Later you can make them visible again by calling setVisible(true).

  • Creating new files in Sun ONE

    I just started learning Java and I downloaded the Sun ONE developers tool. I want to know how to create a new Java file from scratch using the code editor in this tool. I looked through the help and there doesn't seem to be a way to do this. I can edit a file, or ad a file to a project, or create a new folder, or create a new project, but there are no instruction is the help for just creating a plain old ordinary individual Java file. Like I said, I'm new to Java, so I'm starting out small, like one file at t atime. Other than using a mregular run-of-the-mill text editor, is there a way to create new Java files in Sun ONE, and if so, how?

    Hi,
    Click on the Filesystems tab.Then right click the file system node->choose mount.Mount the directory where you need to create your new java file.
    Once the directory is mounted,
    Right click the directory -->choose new --> classes-->Main--->then enter the name of the name ,this willcreate a new java file.
    Hope this helps.

  • Comparing .java files in JBuilder

    Is this possible? I couldn't find this discussed elsewhere on the forum and am curious if and how this can be done. Currently using JBuilder 3.00.
    The problem is that I have two slightly different .java files (applets) where one works and one doesn't. I'd like to have it step through both files and tell me where the differences are (like diff in unix--and no, I don't have a unix platform available to just use that :p ).

    I'm not aware of that feature directly, but it's been awhile since I used JBuilder. Why don't you post to some borland newsgroup and see if any one knows the answer? Most IDEs have some limited version history that will allow you to compare versions of the same file. You could make one copy of the file your first version and the separate copy the second version and then compare ... ... ideally, you'd use a source control application for finding the differences.

  • Want to create and exe file for .java files

    Hello all :)
    I am making a multi-threaded console application.
    It also takes command line parameters from user.
    I want to create .exe files out of .java files.
    Note:- One class contains main method (in default package) and all other classes are in some specific package
    I want to create an exe for the whole application.
    The solutions which i get on net is exe4j but i was unable to use it.
    Please suggest me to create an windows executable file out of java files.
    Thanx in advance

    by definition, if you double click on the .exe , you won't pass it parameters
    you have to launch a shell, reach the directory where the .exe (or .jar) is stored, and launch the exe directly with parameters, e.g:
    myApplication.exe -u user -p password
    you can't double click on the exe and say "ok, i give you -u -p!" ; everything has to be done simultaneously if your app is using the "String [] args" arguments of main
    if you want to specify parameters after launching the app, you have to grab user input in your main

  • How to call java file when entering the another jsp page.

    when i click the link to link to another page, when enter the page, how can i call java file and passing id parameter to call method, which is connected to DB.
    when enter the page, how can i call java file together with one arguement???

    I would strongly suggest to go the MVC way. Please perform all DB operations through a Servlet/Action instead of directly hitting the JSP and then invoking a java bean to do the DB operation. JSP should only do the rendering.

  • How do you run another Java file from a master Java file?

    We're making a game in Java at school, and we need to know how we can run a Java file from another one - like inside the master Java file, we need to have a command to run game.java (something like that). Thanks!

    We're making a game in Java at school, and we need to know how we can run a Java file from another one - like inside the master Java file, we need to have a command to run game.java (something like that). Thanks!One doesn't "run a Java file", and there's no conventional definition of "master Java file". If you want to call the main() method of another class, just make sure the class is in your classpath and call the method. If you want to start up a separate JVM with that class as a process, use Runtime.exec() or similar method.
    ~

  • Decoding .class file into .java file

    How can i decode .class file into .java file?
    can any one suggest the same?

    sekhar145 wrote:
    How can i decode .class file into .java file?by using a decompiler
    JAD is a known one , i am sure there are other on the internet, use you favourite search engine on Java Decompiler
    can any one suggest the same?by using a decompiler
    JAD is a known one , i am sure there are other on the internet, use you favourite search engine on Java Decompiler

  • Jarred .java file, how to use it?

    for a naked .java file, we can use -classpath to import it to our source files.
    but for a jarred .java file, can we import it into our source file for use?
    i tried for few hrs, it is impossible.
    if u have used a jarred .java file before, pls give me a hand.
    thx

    but for a jarred .java file, can we import it into our source file for use?No. And this has nothing to do with jar files at all. You don't import .java files, you import .class files.

Maybe you are looking for