Example of 'Java Servlet Programming, 2nd Edition' (O'reilly)

Hi,
I'm reading 'Java Servlet Programming, 2nd Edition' (O'reilly).
I got a error "'.' expected" and "cannot resolve symbol"
when trying JSP sample, hello3.jsp and HelloBean.java:
I put hello3jsp to webapps/sample, and HelloBean.class
to webapps/sample/WEB-INF/classes .
Is this collect? If true, why I got the error?
Could you give me any advices?
hello3.jsp:
(http://www.servlets.com/jservlet2/examples/ch18/hello3.jsp.txt)
<%-- hello3.jsp --%>
<%@ page import="HelloBean" %>
<jsp:useBean id="hello" class="HelloBean">
  <jsp:setProperty name="hello" property="*" />
</jsp:useBean>
<HTML>
<HEAD><TITLE>Hello</TITLE></HEAD>
<BODY>
<H1>
Hello, <jsp:getProperty name="hello" property="name" />
</H1>
</BODY>
</HTML>HelloBean.java:
(http://www.servlets.com/jservlet2/examples/ch18/HelloBean.java)
public class HelloBean {
  private String name = "World";
  public void setName(String name) {
    this.name = name;
  public String getName() {
    return name;
}Error Message:
org.apache.jasper.JasperException: Unable to compile class for JSP
An error occurred at line: 4 in the jsp file: /hello3.jsp
Generated servlet error:
    [javac] Compiling 1 source file
/usr/local/java/jakarta-tomcat-4.1.18/work/Standalone/localhost/sample/hello3_jsp.java:7: '.' expected
import HelloBean;
                ^
/usr/local/java/jakarta-tomcat-4.1.18/work/Standalone/localhost/sample/hello3_jsp.java:44: cannot resolve symbol
symbol  : class HelloBean
location: class org.apache.jsp.hello3_jsp
      HelloBean hello = null;
      ^regards
maco

I got succeeded!
I changed the three point:
* add 'package hoo;' in HelloBean.java
* add '<%@ page import="my.HelloBean" %>' in hello3.jsp
* change '<jsp:useBean id="hello" class="HelloBean">
to '<jsp:useBean id="hello" class="my.HelloBean">
Before posting, I searched google three times but couldn't get answer.
I could not get well if you didn't give me help...
Thank you very much.

Similar Messages

  • Inputting an excel file to the java servlet program

    Hi,
    How can I input an excel file into the java servlet program? I am using POI HSSF programming to read the content of that excel file.I have created a form that will accept the path from the user and in the servlet program, I have called a post method to retrieve the path of the file. I am getting the path of the file as a string.Then I have to access the file to read the data. But it is not working. What should I do?.Please help me.
    I have created an html file to create a form that will ask the path of the file to be loaded into the servlet program.Please give me a solution,thanks in advance. The servlet program that receives the file is shown below. It just only take the name of the file and prints if that is ok.
    <html>
    <body bgcolor="green">
    <center>
    <form method="post"  action="http://localhost:8080/examples/servlet/Ron1">
    <table>
    <tr>
    <td><B>ENTER THE PATH OF THE FILE</td>
    <td><input type=file name="path"></td>
    </tr>
    </table>
    <input type=submit value= "submit" >
    </form>
    </body>
    </html>
    import java.io.*;
    import javax.servlet.*;
    import java.lang.*;
    import javax.servlet.http.*;
    import java.sql.*;
    import java.text.*;
    import java.util.*;
    import com.oreilly.servlet.MultipartRequest;
    import org.apache.poi.hssf.usermodel.*;
    public class Ron1 extends HttpServlet
       public void doPost(HttpServletRequest request, HttpServletResponse response)   throws IOException, ServletException
            response.setContentType("text/html");
            PrintWriter out = response.getWriter();
            String u = request.getParameter("FileToUpload");
            out.println("The Path is "+u);
            System.out.println("The path is "+u);
            MultipartRequest multi = new MultipartRequest(request,u,10 * 1024 * 1024);
            System.out.println("path is "+u);
            Enumeration files = multi.getFileNames();
            File fUploadedFile = null;
            String sFileName = "";
            out.println("path is "+u);
            while(files.hasMoreElements())
                            String name = (String)files.nextElement();
                            out.println("file is "+name);
                            sFileName = multi.getFilesystemName(name);
                            String type = multi.getContentType(name);
                            fUploadedFile = multi.getFile(name);
                    FileInputStream fis= new FileInputStream(fUploadedFile);
                   HSSFWorkbook wb=new HSSFWorkbook(fis);
                    System.out.println("The path is "+u);
                    out.println("File has identified successfully\n");
                    out.close();
       }

    Hi,
    Can you try to use classes from java.net package (URL, URLConnection) to pass the contents of excel file to servlet?
    HTH
    Vishal

  • Pls give me example of Java Servlet with Oracle

    Hi Guys,
    I am new to Database connectivity of JAVA Servlet with Oracle.
    So can you give me one complete example of connecting Java Servlet with Oracle 9i database.
    [ i mean Select statement, Insert statement..]
    I have tomcat server which comes built-in with NetBeans IDE.
    I need this because, i always come accross messages saying that " you need to change classpath this way " , or " you need to write connection this way "....
    So to avoid all this wrong things..i need your help.
    You guys can reply me on [email protected]
    Thanks & Appreciate..
    Dal Hit

    I got succeeded!
    I changed the three point:
    * add 'package hoo;' in HelloBean.java
    * add '<%@ page import="my.HelloBean" %>' in hello3.jsp
    * change '<jsp:useBean id="hello" class="HelloBean">
    to '<jsp:useBean id="hello" class="my.HelloBean">
    Before posting, I searched google three times but couldn't get answer.
    I could not get well if you didn't give me help...
    Thank you very much.

  • Application Server 4.0 caching the Java Servlet Program

    Hi all,
    I am working with Oracle8i databse and Oracle Application Server 4.0. Now I need to develop some Java Servlet's Program. I successful configure the server and my Servlet program can connect to the Oracle database.
    However, when I make some modification to the program and recompile it. The browser cannot refresh to the modified program. This mean that the content is't update. I think the reason may be the previous program is cached in server.
    Later, I discover using the 'owsctl' utility to reload the application server can solve this problem. However, it is quite inconvenience and not favour to reloasd the server very frequently. And I guess there may have some configuration parameters in the 'OAS Manager' can help me to solve my problem.
    So, anyone can tell me how to solve this problem? Thank you very much.
    Regards

    OAS 4.0.8.1 supports servlets. You need a patch if you implement extra path info feature of servlets. In addition, you have to bounce OAS everytime you upload new servlets. This behavior does not follow the Servlet spec and I don't know when Oracle will fix it. It is a big problem for sites trying to run 24x7.
    <BLOCKQUOTE><font size="1" face="Verdana, Arial">quote:</font><HR>Originally posted by dlnoida:
    Dear All,
    I have an application built in applets, i wants to host them on OAS 4.0.7.
    How can i do it if possible? Do i reqire any third party tool for it ?
    Is OAS 4.0.8 supports servlets?<HR></BLOCKQUOTE>
    null

  • Compiling java servlet programs

    i have Tomcat 5.0 and SDK 1.5 . I am able to compile java programs. But in servlet programs the compiler is unable to recognize the javax.servlet package(the code below). I have pushed all the JAR files of TOMCAT to the CLASSPATH . But nothing has changed.
    javax.servlet.*;
    javax.servlet.Http.*;

    hi,..
    javax.servlet.Http.*; should be javax.servlet.http.*; !
    even though you have put the jar files in the classpath .. does it point to servlet-api.jar ? if it does.. it should work. Also try out specifing the classpath using the -cp while compiling the servlet program .
    --Olakara                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

  • Java servlet programming

    I am the beginner. So would you tell me what should I begin with? what should I need, and how should I do?
    What does this "http:/localhost:8080/servlet/Hello" means?
    Where can I identify the server and the port number?
    Thanks a lot!

    http:/localhost:8080/servlet/Hello
    it means
    http:// protocal
    localhost: ur current machine
    8080 the port no which we give at installation time
    servlet alies name for servlets folder which is recide webserver directory
    hello servlet class name
    u just try this
    1)install first j2sdk1.4.0 (or) later
    ex:
    c:\j2sdk1.4.0
    2)install second tomcat5.0
    ex:
    c:\tomcat5.0
    3) place the cursor on mycomputer and right click properties --> advance
         |
         environment (click this)
         |
         new
         |
         JAVA_HOME c:\j2sdk1.4.0 (ok,ok)
         new
         |
         CATALINA_HOME c:\tomcat5.0
         click path
         |
         (add at end) ;c:\j2sdk1.4.0\bin;c:\tomcat5.0\bin;
         new
         |
         CLASSPATH %classpath%;.;c:\tomcat5.0\common\lib\servlet-api.jar;
         now u restart the computer (or) tomcat server
         then in browser
         http://localhot:8080

  • Java servlet class access

    Can a servlet running on server A access a class defined on server B?
    More information:
    I am new at Java servlet programming and want to make sure that my web application is secure. I have set up a Java class that returns some user information (name, email address etc) and I have set up some jsp and servlet pages that access the class via an 'import my.class...' for servlets and a '@page import ="my.class..." 'for jsp. The jsp and servlet pages do session checking and authentication but the class does none of that - it's methods just return the requested data. I do not want to put any authentication in the class but I want to be certain that there is no way some other web server out on the internet could access this class in my web application. I do not think it is possible but my fear is that some hacker out there could somehow remotely do an @page import "my.class..." on my webserver and then gain access to my class methods? These web apps are running inside a Glassfish 3.0 app server.
    Thanks!

    user479480 wrote:
    That is very helpful info. I have been writing a lot of functional type code (updating, selecting and returning database data etc) inside Java servlets but when I get a new requirement I end up rewriting the same code in new servlet pages. So I have been thinking of putting all of that functional code in classes that I can re-use but was unsure of the security access and did not want to clutter the classes up with a bunch of session/authentication checking.
    Do you recommend any books on J2EE Web programming? Thanks again for your assistance.Code re-use isn't a problem that way, because you can put your common code into a library jar and use it in as many JVMs as you like. What you can't do is to access any Java objects running in one JVM from another one, whether or not they are on the same machine.

  • Java Servlet installation problem

    We have a Java Servlet program.
    To move into OAS.
    1.We need to configure the catridge(Done)
    2.We have to set the run time environment(I couldn't get this
    one)
    Oracle says two different methodology,
    1. From JDeveloper point of view
    2. From OAS point of view,
    I am not very clear in setting the environment variables and
    moving the files.
    Regards
    Nirmal
    null

    Hi,
    I think your problem has to do with your classpath. When compiling java classes, you must specify a classpath that the compiler will use to resolve your import statments. Since you are compiling a servlet, you must include the jar file that contains the javax.servlet package. Since you've installed the j2sdkee 1.3.1, you'll find the javax.serlvet package within the j2ee.jar file within the J2SDKEE 1.3.1 lib directory. So your javac command should look like this:
    javac -classpath <j2sdkee1.3.1 directory>/lib/j2ee.jar Test.java
    ( where j2sdkee1.3.1 directory is the path to where you installed the j2sdkee 1.3.1 ).
    I hope this helps?
    Cheers
    Jeff

  • MySQL and Java - getting program to work

    I am setting up mysql to run sql from a Java program on my pc at home and probably biting off more than I can chew. I get these messages when executing the java program ExecuteSQL.java:
    Exception in thread "main" java.lang.NoClassDefFoundError: Test2 <wrong name: MyProjects/test2/Test2>
    at java.lang.ClassLoader.defineClass0<Native Method>
    at java.lang.ClassLoader.defineClass<Unknown Source>
    at java.security.SecurityClassLoader.defineClass<Unknown Source>
    at java.net.URLClassLoader.defineClass<Unknown Source>
    at java.net.URLClassLoader.access$100<Unknown Source>
    at java.net.URLClassLoader$1.run<Unknown Source>
    at java.security.AccessController.ddPrivileged<Native Method>
    at java.lang.ClassLoader.findClass<Unknown Source>
    at java.lang.ClassLoader.loadClass<Unknown Source>
    at sun.misc.Launcher$AppClassLoader.loadClass<Unknown Source>
    at java.lang.ClassLoader.loadClass<Unknown Source>
    at java.lang.ClassLoader.loadClassInternal<Unknown Source>
    This is what I did.
    I created a folder on my C: drive named MySQL.
    I downloaded these two zip files form the MySQL website
         * mysql-connector-java-3.0.11-stable
         * mysql-4.0.18-win.zip
    Installed both of these in folder MySQL.
    I modified this line in the program ("ExecuteSQL" 1st pgm in chapter 17) I got from "Java Examples In a Nutshell" and compiled it into directory jwork.
    String driver = "com.mysql.jdbc.driver", url = "jdbc:mysql://", user = "", password = "";
    The readme file talks about putting a jar file in $JAVA_HOME/jre/lib/ext.
    the word "Java_Home" (I now know) is not literally the name but represents the
    name of the folder where the JDK to be used exists. So I put a copy of
    mysql-connector-java-3.0.11-stable-bin.jar in folder C:\JDK14/jre/lib/ext.
    Then I get a ClassNotFoundException error com.mysql.jdbc.driver.
    After finding
    http://forum.java.sun.com/thread.jsp?forum=31&thread=439796
    and
    http://forum.java.sun.com/thread.jsp?forum=31&thread=499888
    and others, I copied (a second copy) the jar file to the directory where I am create my java objects.
    Then I unzipped it to that directory, creating three folders that hold the unzipped objects.
    I tried executing the program again. I get the messages at the top of this post.
    The Manifest file is in one of the three folders unzipped to my java work directory.
    In the second of the two above threads, jsalonen says:
    the problem can be solved by mentioning mysql.jar in the Class-Path attribute
    in the manifest of the jar file:
    In this "manifest" file, there are only three lines and I added a fourth and it looks like this
    (there are two, one in directory MySQL\META-INF and one in directory jwork\META-INF:
    Manifest-Version: 1.0
    Ant-Version: Apache Ant 1.6.1
    Created-By: 1.4.0_01-b03 (Sun Microsystems Inc.)
    Main-Class:jwork\ExecuteSQL
    How do I "mention" mysql.jar in the class path attribute?
    In the index.list file (in the directory with the manifest file, do I need to add anything to refer that "com.mysql.jdbc.driver" is the driver?
    Do I need index.list in MySQL\META-INF ?
    Thank you for your help. The program ExecuteSQL follows.
    * Copyright (c) 2000 David Flanagan. All rights reserved.
    * This code is from the book Java Examples in a Nutshell, 2nd Edition.
    * It is provided AS-IS, WITHOUT ANY WARRANTY either expressed or implied.
    * You may study, use, and modify it for any non-commercial purpose.
    * You may distribute it non-commercially as long as you retain this notice.
    * For a commercial use license, or to purchase the book (recommended),
    * visit http://www.davidflanagan.com/javaexamples2.
    /** package com.davidflanagan.examples.sql; */
    import java.sql.*;
    import java.io.*;
    * A general-purpose SQL interpreter program.
    public class ExecuteSQL {
    public static void main(String[] args) {
    Connection conn = null; // Our JDBC connection to the database server
    try {
    String driver = "com.mysql.jdbc.driver", url = "jdbc:mysql://",
    user = "", password = "";
    // Parse all the command-line arguments
    for(int n = 0; n < args.length; n++) {
    if (args[n].equals("-d")) driver = args[++n];
    else if (args[n].equals("-u")) user = args[++n];
    else if (args[n].equals("-p")) password = args[++n];
    else if (url == null) url = args[n];
    else throw new IllegalArgumentException("Unknown argument.");
    // The only required argument is the database URL.
    if (url == null)
    throw new IllegalArgumentException("No database specified");
    // If the user specified the classname for the DB driver, load
    // that class dynamically. This gives the driver the opportunity
    // to register itself with the DriverManager.
    if (driver != null) Class.forName(driver);
    // Now open a connection the specified database, using the
    // user-specified username and password, if any. The driver
    // manager will try all of the DB drivers it knows about to try to
    // parse the URL and connect to the DB server.
    conn = DriverManager.getConnection(url, user, password);
    // Now create the statement object we'll use to talk to the DB
    Statement s = conn.createStatement();
    // Get a stream to read from the console
    BufferedReader in =
              new BufferedReader(new InputStreamReader(System.in));
    // Loop forever, reading the user's queries and executing them
    while(true) {
    System.out.print("sql> "); // prompt the user
    System.out.flush(); // make the prompt appear now.
    String sql = in.readLine(); // get a line of input from user
    // Quit when the user types "quit".
    if ((sql == null) || sql.equals("quit")) break;
    // Ignore blank lines
    if (sql.length() == 0) continue;
    // Now, execute the user's line of SQL and display results.
    try {
    // We don't know if this is a query or some kind of
    // update, so we use execute() instead of executeQuery()
    // or executeUpdate() If the return value is true, it was
    // a query, else an update.
    boolean status = s.execute(sql);
              // Some complex SQL queries can return more than one set
              // of results, so loop until there are no more results
    do {
    if (status) { // it was a query and returns a ResultSet
    ResultSet rs = s.getResultSet(); // Get results
    printResultsTable(rs, System.out); // Display them
    else {
    // If the SQL command that was executed was some
    // kind of update rather than a query, then it
    // doesn't return a ResultSet. Instead, we just
    // print the number of rows that were affected.
    int numUpdates = s.getUpdateCount();
    System.out.println("Ok. " + numUpdates +
                             " rows affected.");
    // Now go see if there are even more results, and
    // continue the results display loop if there are.
    status = s.getMoreResults();
    } while(status || s.getUpdateCount() != -1);
    // If a SQLException is thrown, display an error message.
    // Note that SQLExceptions can have a general message and a
    // DB-specific message returned by getSQLState()
    catch (SQLException e) {
    System.err.println("SQLException: " + e.getMessage()+ ":" +
                        e.getSQLState());
    // Each time through this loop, check to see if there were any
    // warnings. Note that there can be a whole chain of warnings.
    finally { // print out any warnings that occurred
              SQLWarning w;
    for(w=conn.getWarnings(); w != null; w=w.getNextWarning())
    System.err.println("WARNING: " + w.getMessage() +
                             ":" + w.getSQLState());
    // Handle exceptions that occur during argument parsing, database
    // connection setup, etc. For SQLExceptions, print the details.
    catch (Exception e) {
    System.err.println(e);
    if (e instanceof SQLException)
    System.err.println("SQL State: " +
                        ((SQLException)e).getSQLState());
    System.err.println("Usage: java ExecuteSQL [-d <driver>] " +
                   "[-u <user>] [-p <password>] <database URL>");
    // Be sure to always close the database connection when we exit,
    // whether we exit because the user types 'quit' or because of an
    // exception thrown while setting things up. Closing this connection
    // also implicitly closes any open statements and result sets
    // associated with it.
    finally {
    try { conn.close(); } catch (Exception e) {}
    * This method attempts to output the contents of a ResultSet in a
    * textual table. It relies on the ResultSetMetaData class, but a fair
    * bit of the code is simple string manipulation.
    static void printResultsTable(ResultSet rs, OutputStream output)
         throws SQLException
    // Set up the output stream
    PrintWriter out = new PrintWriter(output);
    // Get some "meta data" (column names, etc.) about the results
    ResultSetMetaData metadata = rs.getMetaData();
    // Variables to hold important data about the table to be displayed
    int numcols = metadata.getColumnCount(); // how many columns
    String[] labels = new String[numcols]; // the column labels
    int[] colwidths = new int[numcols]; // the width of each
    int[] colpos = new int[numcols]; // start position of each
    int linewidth; // total width of table
    // Figure out how wide the columns are, where each one begins,
    // how wide each row of the table will be, etc.
    linewidth = 1; // for the initial '|'.
    for(int i = 0; i < numcols; i++) {             // for each column
    colpos[i] = linewidth; // save its position
    labels[i] = metadata.getColumnLabel(i+1); // get its label
    // Get the column width. If the db doesn't report one, guess
    // 30 characters. Then check the length of the label, and use
    // it if it is larger than the column width
    int size = metadata.getColumnDisplaySize(i+1);
    if (size == -1) size = 30; // Some drivers return -1...
         if (size > 500) size = 30; // Don't allow unreasonable sizes
    int labelsize = labels.length();
    if (labelsize > size) size = labelsize;
    colwidths[i] = size + 1; // save the column the size
    linewidth += colwidths[i] + 2; // increment total size
    // Create a horizontal divider line we use in the table.
    // Also create a blank line that is the initial value of each
    // line of the table
    StringBuffer divider = new StringBuffer(linewidth);
    StringBuffer blankline = new StringBuffer(linewidth);
    for(int i = 0; i < linewidth; i++) {
    divider.insert(i, '-');
    blankline.insert(i, " ");
    // Put special marks in the divider line at the column positions
    for(int i=0; i<numcols; i++) divider.setCharAt(colpos[i]-1,'+');
    divider.setCharAt(linewidth-1, '+');
    // Begin the table output with a divider line
    out.println(divider);
    // The next line of the table contains the column labels.
    // Begin with a blank line, and put the column names and column
    // divider characters "|" into it. overwrite() is defined below.
    StringBuffer line = new StringBuffer(blankline.toString());
    line.setCharAt(0, '|');
    for(int i = 0; i < numcols; i++) {
    int pos = colpos[i] + 1 + (colwidths[i]-labels[i].length())/2;
    overwrite(line, pos, labels[i]);
    overwrite(line, colpos[i] + colwidths[i], " |");
    // Then output the line of column labels and another divider
    out.println(line);
    out.println(divider);
    // Now, output the table data. Loop through the ResultSet, using
    // the next() method to get the rows one at a time. Obtain the
    // value of each column with getObject(), and output it, much as
    // we did for the column labels above.
    while(rs.next()) {
    line = new StringBuffer(blankline.toString());
    line.setCharAt(0, '|');
    for(int i = 0; i < numcols; i++) {
    Object value = rs.getObject(i+1);
              if (value != null)
              overwrite(line, colpos[i] + 1, value.toString().trim());
    overwrite(line, colpos[i] + colwidths[i], " |");
    out.println(line);
    // Finally, end the table with one last divider line.
    out.println(divider);
    out.flush();
    /** This utility method is used when printing the table of results */
    static void overwrite(StringBuffer b, int pos, String s) {
    int slen = s.length(); // string length
    int blen = b.length(); // buffer length
    if (pos+slen > blen) slen = blen-pos; // does it fit?
    for(int i = 0; i < slen; i++) // copy string into buffer
    b.setCharAt(pos+i, s.charAt(i));

    Don't put those JARs in the lib/ext directory. Only language extensions (e.g., packages that start with "javax") belong in there.
    Learn how to set the CLASSPATH properly for starters:
    http://java.sun.com/j2se/1.4.2/docs/tooldocs/windows/classpath.html
    You might want to look at the JDBC tutorial, too:
    http://java.sun.com/docs/books/tutorial/jdbc/
    Do one thing at a time. Get the program to work, then worry about packaging it into an executable JAR.

  • Problem in compiling aa servlet program

    I have installed jsdk1.4.2_13
    And also installed tomcat 5.0.28
    I have set
    CATALINA_HOME==C:\Program Files\Tomcat\jakarta-tomcat-5.0.28
    JAVA_HOME ==C:\j2sdk1.4.2_13
    CLASS_PATH==
    C:\Program Files\Tomcat\jakarta-tomcat-5.0.28\common\lib\servlet-api.jar;
    C:\Program Files\Tomcat\jakarta-tomcat-5.0.28\common\lib\jsp-api.jar
    PATH ==C:\j2sdk1.4.2_13\bin;C:\Program Files\Tomcat\jakarta-tomcat-5.0.28\bin;%SystemRoot%\system32;%SystemRoot%;%SystemRoot%\System32\Wbem
    -->My java programs are compiling
    -->I can run tomcat server , And also can see starting page of "http://localhost:8080/"
    But I am not able to compile servlet program
    MY sevlet program is
    import java.io.*;
    import javax.servlet.*;
    import javax.servlet.http.*;
    public class HelloServlet extends HttpServlet {
    public void doGet(HttpServletRequest request,
    HttpServletResponse response)
    throws ServletException, IOException {
    response.setContentType("text/html");
    PrintWriter out = response.getWriter();
    String docType =
    "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0 " +
    "Transitional//EN\">\n";
    out.println(docType +
    "<HTML>\n" +
    "<HEAD><TITLE>Hello</TITLE></HEAD>\n" +
    "<BODY BGCOLOR=\"#FDF5E6\">\n" +
    "<H1>Hello</H1>\n" +
    "</BODY></HTML>");
    ERRORS are:
    Pakage javax.servlet does not exist
    Pakage javax.servlet.http does not exist
    cannot resolve symbol HttpServletRequest
    and similar errors
    can anyone guide me?
    Message was edited by:
    Learn

    it's not CLASS_PATH, it's CLASSPATH.
    Directory paths with spaces in them are problematic. Surround them with double quotes.
    I think the best thing is not a CLASSPATH environment variable. Better to use the -classpath option on javac.exe when you compile.
    So your command to compile might look something like:
    javac -classpath .;"C:\Program Files\Tomcat\jakarta-tomcat-5.0.28\common\lib\servlet-api.jar" *.java%

  • Questions about Java Servlets and JSP

    Hi,
    I'm a confident Java Programmer (and really enjoy using this language) but am very new to Java servlets and Java Server Pages.
    I have previously worked with Perl on my web projects (simple 'league' style voting pages). I read in my 'Core Java' book that I should no longer use perl or even cgi.
    I need to know more about Java servlets and Java Server Pages so I can make the switch to a 'real' programming language.
    I have a few questions:
    How should I start to learn JS and JSP?
    How applicable will the java knowlegdge I have already be?
    Are JSP common on the world wide web?
    What tools do I need to start? (I currently develop in JBuilder and have Java 1.4.1 Standard Edition)
    Is it likey my web host (and others) will support JSP?
    Thank-you very much for helping a novice get started,
    Regards,
    Paul

    Hi, Steve ...has to be frustrating! But do not despair.
    Let's suppose the servlet it's named MyServlet on package org.servlets
    WEB-INF should look:
    WEB-INF
    classes
    org
    servlets
    MyServlet.class
    web.xml
    web.xml file should have this two declarations:
    <web-app>
      <servlet>
        <servlet-name>MyServlet</servlet-name>
        <servlet-class>org.servlets.MyServlet</servlet-class>
      </servlet>
      <!-- other servlets -->
      <servlet-mapping>
        <servlet-name>MyServlet</servlet-name>
        <url-pattern>/MyServlet</url-pattern>
      </servlet-mapping>
      <!-- other servlets mappings -->
    </web-app>Now, once the container starts (Tomcat?), you should be able to see that servlet in:
    http://localhost:8080/[my-context/]MyServletAnd what my-context is? The web application context. This string should be empty if your're deploying to the root context, otherwise should the context name. In Tomcat, deploying to root context defaults to using webapps/ROOT.
    Sorry for my English, but I felt the need to answer your request. I hope it helps despite my writing.

  • Logical error 2nd Edition... :~(

    here is the 2nd edition of the program.
    it runs wired, i can't exactly tell how, but the way it does just like lost-control.
    copy it and give it a try see if you have any idea what's going on.
    p.s. all called methods are sticked after the main program.
    class DecodeDriver
         public static void main(String[] args)
              char keyin;
              do
                   sop("**********************************************");
                   sop("**********************************************");
                   sop("**            M A I N   M E N U             **");
                   sop("**        ~~~~~~~~~~~~~~~~~~~~~~~~          **");
                   sop("** ======================================== **");
                   sop("** M) Morse Code                            **");
                   sop("** C) Caesar Cipher                         **");
                   sop("** V) Vignere Cipher                        **");
                   sop("** P) Playfair Cipher                       **");
                   sop("** ---------------------------------------- **");
                   sop("** X) Exit Program                          **");
                   sop("**                                          **");
                   sop("**********************************************");
                   sop("**********************************************");
                   sop(" ");
                   sop("Please select an encoding scheme: ");
                   keyin = SavitchIn.readNonwhiteChar();
                   switch(keyin)
                   case'M':
                   case'm': Morse();
                        break;
                        case'C':
                   case'c': Caesar();
                        break;
                        case'V':
                   case'v': Vignere();
                        break;
                        case'P':
                   case'p': Playfair();
                        break;
                        case'X':
                        case'x': sop("Thanks for using! Bye!");
                        break;
                        default: sop("Invalid Key Entered. Please select one from the menu.");
                        break;
                   } //switch
              } // do
              while(keyin != 'X' && keyin != 'x');
              System.exit(0);
         } // main
              public static void Morse()
                   char subKeyin;
                   sop("**********************************************");
                   sop("**********************************************");
                   sop("**            Morse Code Menu               **");
                   sop("**        ~~~~~~~~~~~~~~~~~~~~~~~~          **");
                   sop("** ======================================== **");
                   sop("** E) Encode                                **");
                   sop("** D) Decode                                **");
                   sop("** ---------------------------------------- **");
                   sop("** X) Return to Main Program                **");
                   sop("**                                          **");
                   sop("**********************************************");
                   sop("**********************************************");
                   sop(" ");
                   sop("Please select to encoding / decoding: ");
                   subKeyin = SavitchIn.readNonwhiteChar();
                   switch(subKeyin)
                        case'E':
                        case'e': MorseCode.encode();
                        break;
                        case'D':
                        case'd': MorseCode.decode();
                        break;
                        case'X':
                        case'x': sop("Returning to main menu...");
                                   break;
                        default: sop("Invalid Key Entered. Please select one from the menu.");
                                       break;
                   } // switch
              } //Morse
              private static void Caesar()
                   char subKeyin = SavitchIn.readNonwhiteChar();
                   sop("**********************************************");
                   sop("**********************************************");
                   sop("**           Caesar Cipher Menu             **");
                   sop("**        ~~~~~~~~~~~~~~~~~~~~~~~~          **");
                   sop("** ======================================== **");
                   sop("** E) Encode                                **");
                   sop("** D) Decode                                **");
                   sop("** ---------------------------------------- **");
                   sop("** X) Return to Main Program                **");
                   sop("**                                          **");
                   sop("**********************************************");
                   sop("**********************************************");
                   sop(" ");
                   sop("Please select to encoding / decoding: ");
                   switch(subKeyin)
                        case'E':
                        case'e': CaesarCipher.encode();
                        case'D':
                        case'd': CaesarCipher.decode();
                        case'X':
                        case'x': sop("Returning to main menu...");
                                   break;
                        default: sop("Invalid Key Entered. Please select one from the menu.");
                   } // switch
              } //CaesarCipher
              private static void Vignere()
                   char subKeyin = SavitchIn.readNonwhiteChar();
                   sop("**********************************************");
                   sop("**********************************************");
                   sop("**           Vignere Cipher Menu             **");
                   sop("**        ~~~~~~~~~~~~~~~~~~~~~~~~          **");
                   sop("** ======================================== **");
                   sop("** E) Encode                                **");
                   sop("** D) Decode                                **");
                   sop("** ---------------------------------------- **");
                   sop("** X) Return to Main Program                **");
                   sop("**                                          **");
                   sop("**********************************************");
                   sop("**********************************************");
                   sop(" ");
                   sop("Please select to encoding / decoding: ");
                   switch(subKeyin)
                        case'E':
                        case'e': VignereCipher.encode();
                        case'D':
                        case'd': VignereCipher.decode();
                        case'X':
                        case'x': sop("Returning to main menu...");
                                   break;
                        default: sop("Invalid Key Entered. Please select one from the menu.");
                   } // switch
              } //VignereCipher          
              private static void Playfair()
                   char subKeyin = SavitchIn.readNonwhiteChar();
                   sop("**********************************************");
                   sop("**********************************************");
                   sop("**          Playfair Cipher Menu            **");
                   sop("**        ~~~~~~~~~~~~~~~~~~~~~~~~          **");
                   sop("** ======================================== **");
                   sop("** E) Encode                                **");
                   sop("** D) Decode                                **");
                   sop("** ---------------------------------------- **");
                   sop("** X) Return to Main Program                **");
                   sop("**                                          **");
                   sop("**********************************************");
                   sop("**********************************************");
                   sop(" ");
                   sop("Please select to encoding / decoding: ");
                   switch(subKeyin)
                        case'E':
                        case'e': PlayfairCipher.encode();
                        case'D':
                        case'd': PlayfairCipher.decode();
                        case'X':
                        case'x': sop("Returning to main menu...");
                                   break;
                        default: sop("Invalid Key Entered. Please select one from the menu.");
                   } // switch
              } //PlayfairCipher     
              private static void sop(String newString)
                   System.out.println(newString);
              } // sop
    } //class
    (part of)the SavitchIn input stuff:
        public static char readNonwhiteChar( )
          char next;
          next = readChar( );
          while (Character.isWhitespace(next))
              next = readChar( );
          return next;
         The following methods are not used in the text, except
         for a brief reference in Chapter 2. No program code uses
         them. However, some programmers may want to use them.
         Precondition: The next input in the stream consists of
         an int value, possibly preceded by whitespace, but
         definitely followed by whitespace.
         Action: Reads the first string of nonwhitespace characters
         and returns the int value it represents. Discards the
         first whitespace character after the word. The next read
         takes place immediately after the discarded whitespace.
         In particular, if the word is at the end of a line, the
         next read will take place starting on the next line.
         If the next word does not represent an int value,
         a NumberFormatException is thrown.
    MorseCode.java - for debugin' propose.
    class MorseCode
       public MorseCode()
          sop("unfinished - const.");
         }//const.
         public static void encode()
              sop("unfinished - encode");
              char newchar;
              newchar = SavitchIn.readChar();
              System.out.println(newchar);
         public static void decode()
              sop("unfinished - decode");
         private static void sop(String newString)
              System.out.println(newString);
         } // sop
    }//class

    aside from the missing breaks?
    encode OR decode
    case'E':
    case'e': CaesarCipher.encode();
    break;
    case'D':
    case'd': CaesarCipher.decode();
    break;looks better this time?
    class DecodeDriver
         public static void main(String[] args)
              char keyin;
              do
                   sop("**********************************************");
                   sop("**********************************************");
                   sop("**            M A I N   M E N U             **");
                   sop("**        ~~~~~~~~~~~~~~~~~~~~~~~~          **");
                   sop("** ======================================== **");
                   sop("** M) Morse Code                            **");
                   sop("** C) Caesar Cipher                         **");
                   sop("** V) Vignere Cipher                        **");
                   sop("** P) Playfair Cipher                       **");
                   sop("** ---------------------------------------- **");
                   sop("** X) Exit Program                          **");
                   sop("**                                          **");
                   sop("**********************************************");
                   sop("**********************************************");
                   sop(" ");
                   sop("Please select an encoding scheme: ");
                   keyin = SavitchIn.readNonwhiteChar();
                   switch(keyin)
                   case'M':
                   case'm': Morse();
                        break;
                   case'C':
                   case'c': Caesar();
                        break;
                   case'V':
                   case'v': Vignere();
                        break;
                   case'P':
                   case'p': Playfair();
                        break;
                   case'X':
                   case'x': sop("Thanks for using! Bye!");
                        break;
                   default: sop("Invalid Key Entered. Please select one from the menu.");
                        break;
                   } //switch
              } // do
              while(keyin != 'X' && keyin != 'x');
              System.exit(0);
         } // main
              public static void Morse()
                   char subKeyin;
                   sop("**********************************************");
                   sop("**********************************************");
                   sop("**            Morse Code Menu               **");
                   sop("**        ~~~~~~~~~~~~~~~~~~~~~~~~          **");
                   sop("** ======================================== **");
                   sop("** E) Encode                                **");
                   sop("** D) Decode                                **");
                   sop("** ---------------------------------------- **");
                   sop("** X) Return to Main Program                **");
                   sop("**                                          **");
                   sop("**********************************************");
                   sop("**********************************************");
                   sop(" ");
                   sop("Please select to encoding / decoding: ");
                   subKeyin = SavitchIn.readNonwhiteChar();
                   switch(subKeyin)
                        case'E':
                        case'e': MorseCode.encode();
                        break;
                        case'D':
                        case'd': MorseCode.decode();
                        break;
                        case'X':
                        case'x': sop("Returning to main menu...");
                        break;
                        default: sop("Invalid Key Entered. Please select one from the menu.");
                        break;
                   } // switch
              } //Morse
              private static void Caesar()
                   char subKeyin;
                   sop("**********************************************");
                   sop("**********************************************");
                   sop("**           Caesar Cipher Menu             **");
                   sop("**        ~~~~~~~~~~~~~~~~~~~~~~~~          **");
                   sop("** ======================================== **");
                   sop("** E) Encode                                **");
                   sop("** D) Decode                                **");
                   sop("** ---------------------------------------- **");
                   sop("** X) Return to Main Program                **");
                   sop("**                                          **");
                   sop("**********************************************");
                   sop("**********************************************");
                   sop(" ");
                   sop("Please select to encoding / decoding: ");
                   subKeyin =  SavitchIn.readNonwhiteChar();
                   switch(subKeyin)
                        case'E':
                        case'e': CaesarCipher.encode();
                        break;
                        case'D':
                        case'd': CaesarCipher.decode();
                        break;
                        case'X':
                        case'x': sop("Returning to main menu...");
                                   break;
                        default: sop("Invalid Key Entered. Please select one from the menu.");
                                       break;
                   } // switch
              } //CaesarCipher
              private static void Vignere()
                   char subKeyin;
                   sop("**********************************************");
                   sop("**********************************************");
                   sop("**           Vignere Cipher Menu             **");
                   sop("**        ~~~~~~~~~~~~~~~~~~~~~~~~          **");
                   sop("** ======================================== **");
                   sop("** E) Encode                                **");
                   sop("** D) Decode                                **");
                   sop("** ---------------------------------------- **");
                   sop("** X) Return to Main Program                **");
                   sop("**                                          **");
                   sop("**********************************************");
                   sop("**********************************************");
                   sop(" ");
                   sop("Please select to encoding / decoding: ");
                   subKeyin  = SavitchIn.readNonwhiteChar();
                   switch(subKeyin)
                        case'E':
                        case'e': VignereCipher.encode();
                        break;
                        case'D':
                        case'd': VignereCipher.decode();
                        break;
                        case'X':
                        case'x': sop("Returning to main menu...");
                        break;
                        default: sop("Invalid Key Entered. Please select one from the menu.");
                        break;
                   } // switch
              } //VignereCipher          
              private static void Playfair()
                   char subKeyin;
                   sop("**********************************************");
                   sop("**********************************************");
                   sop("**          Playfair Cipher Menu            **");
                   sop("**        ~~~~~~~~~~~~~~~~~~~~~~~~          **");
                   sop("** ======================================== **");
                   sop("** E) Encode                                **");
                   sop("** D) Decode                                **");
                   sop("** ---------------------------------------- **");
                   sop("** X) Return to Main Program                **");
                   sop("**                                          **");
                   sop("**********************************************");
                   sop("**********************************************");
                   sop(" ");
                   sop("Please select to encoding / decoding: ");
                   subKeyin  = SavitchIn.readNonwhiteChar();
                   switch(subKeyin)
                        case'E':
                        case'e': PlayfairCipher.encode();
                        break;
                        case'D':
                        case'd': PlayfairCipher.decode();
                        break;
                        case'X':
                        case'x': sop("Returning to main menu...");
                        break;
                        default: sop("Invalid Key Entered. Please select one from the menu.");
                        break;
                   } // switch
              } //PlayfairCipher     
              private static void sop(String newString)
                   System.out.println(newString);
              } // sop
    } //class

  • User Role problems in Sun Java Application Server Platform Edition 8

    I am having two problems setting up user roles in Sun Java Application Server Platform Edition 8. At first, I thought that it was a problem with the higher level features that I was using, so I created a very simple example using the simplest authentication I can use, but the problem still occurs. I am using the file realm and configuring the users in the App Server Admin Console. I create 2 users in different roles. One user should have access, the other should not.
    1) The first problem is that both users can access the page
    2) The second problem is that the isUserInRole() method returns false for both users with the role that it should be authenticating against.
    Here is a sample of my code:
    Users Configured in Console:
    username password roles
    user1 ********** admin
    user2 ********** noaccess
    web.xml
         <security-role>
              <role-name>admin</role-name>
         </security-role>
         <security-constraint>
              <web-resource-collection>
                   <web-resource-name>My Protected Area</web-resource-name>
                   <url-pattern>/*</url-pattern>
              </web-resource-collection>
              <auth-constraint>
                   <role-name>admin</role-name>
              </auth-constraint>
              <user-data-constraint>
                   <transport-guarantee>NONE</transport-guarantee>
              </user-data-constraint>
         </security-constraint>
         <login-config>
              <auth-method>BASIC</auth-method>
              <realm-name>file</realm-name>
         </login-config>
         <servlet>
              <servlet-name>
                   TestServlet
              </servlet-name>
              <servlet-class>
                   mypackage.TestServlet
              </servlet-class>
              <security-role-ref>
                   <role-name>admin</role-name>
                   <role-link>admin</role-link>
              </security-role-ref>
         </servlet>
         <servlet-mapping>
              <servlet-name>
                   TestServlet
              </servlet-name>
              <url-pattern>
                   /TestServlet
              </url-pattern>
         </servlet-mapping>
    TestServlet.java:
              out.println("admin role: " + request.isUserInRole("admin") + "<BR/>");
    Thanks before hand for any responses.
    - Brian

    Hi Jeanfrancois,
    Your suggestion has lead me to find my problem. There were actually three problems.
    1) First, you suggestion to reorder my xml file did not cause any errors to occur. I got suspicious that my web.xml file was wrong. I looked at some sample web-xml files and found that I was missing the header as follows:
    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE web-app PUBLIC '-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN' 'http://java.sun.com/dtd/web-app_2_3.dtd'>
    2) When I added this information, the deploy feature failed stating the my web.xml file was out of order. I fixed the ordering. It now deployed, but the security still wasn't working.
    3) I then added the sun-web.xml file. This file was missing before hand as I thought it was unnessary. However, this file added the essential mapping from a role to a group. After adding this, it now started to work.
    Thanks so much for you time and effort. You really did help me.
    - Brian Blank

  • I have jsdk2, but I can't compile servlet program

    I have jsdk2 version. which create in my c:\ dirve a folder jdk1.3. I do all the program from that. But I found that some of the class files of Servlet (servletRespose etc ) is missing. What I do to recover that. Even I can't compile any servlet program from that. Pls reply to my problems.
    Regards.
    Ranjan

    The Servlet API is part of J2EE (Java 2 Enterprise Edition). It is not included in the Standard Edition.
    So you need to download and install the J2EE reference implementation or another servlet engine such as Apache Tomcat ( http://jakarta.apache.org/tomcat ). Don't forget to put the Tomcat JAR files in your CLASSPATH when compiling your servlet program.
    Jesper

  • Please help me to use javamail to send mail in servlet program

    hi
    i want to send simple mail from user [email protected] to user [email protected] using servlet program
    i can't compile the javamail demo program servlet "JavaMailServlet.java".
    i have this exception
    Note: SendMailServlet.java uses or overrides a deprecated API.
    Note: Recompile with -deprecation for details.
    i don't no how to do
    please help me if you have code
    thank's

    Given that you're having problems with your [url http://forum.java.sun.com/thread.jsp?forum=43&thread=536278&tstart=0&trange=30]demo mail code as well as your demo servlet code, perhaps you would be better served by learning about JavaMail, servlets, and perhaps Java in general (for example - the meaning of deprecated). Then you may be able to build your own servlet for handling mail or at least will be able to revise the demo code found elsewhere.
    Of course, if the purpose is really not to learn how to use Java, JavaMail, servlets, etc. but to simply create something that works then you could always hire someone to write the program for you.
    This is not intended to be rude or anything - just an observation and some food for thought.
    &#8734; brewman &#8734;

Maybe you are looking for

  • IPod Touch is stuck on "Connect To iTunes" screen

    My iPod Touch won't turn on correctly. I'm able to reset it, and then turn it back on. But when I turn it back on it says that it needs to be connected with iTunes. So when I plug in my iPod, it comes up on iTunes saying that my iPod could not be reg

  • Start a java program from an FMB then read and write some variables

    Hello, I am trying to see whether the following setup works: item A, B, D and Button Z are on a Forms Canvas. User clicks on Button Z. This will launch a java program (Myprog class). Myprog main will read values in item A and B, run some calculation

  • My ichat lost it's freaken mind... im ******... please help

    this morning... my computer ran out of battery... so it died. I hook it up to a power source and then my ichat starts up likes it's the first time... with the 'welcome to ichat' ... so i click continue and my buddy list pops up and everything looks f

  • IPad Air and random crashes

    Greetings, I'm now on my 3rd iPad (still have my original iPad, and an iPad 3), and just bought an iPad Air, so I've been around them since their inception. I must admit that I've never had any issues with my iPads, until I purchased this Air. I don'

  • Installed mavericks ok, but iMovie 10 will not install because of video card deficiency.

    I installed mavericks without difficulty on my 2007 iMac.  However I can not install iMovie 10 that comes with Mavericks.  The prompt tell me that my video cards are inadequate.  Can I upgrade the video cards, and if so how costly will it be? Denny B