tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From David Smith <d...@cornell.edu>
Subject Re: error with javac
Date Mon, 03 Dec 2007 18:39:33 GMT
1. You didn't include a package directive in your source.  You really 
should package your sources.

2. How are you compiling these?  Most people use an IDE or let a build 
tool like maven or ant do the ugly heavy lifting for them.  From your 
description you seem to be doing this by hand.  NetBeans, Eclipse, 
Maven, and Ant are all free.  NetBeans and Eclipse are both very good 
IDEs that'll make your life much easier.

--David

rameau rameau1982 wrote:
> hi, I have 2 java classes in the same directory. One of them 
> (SlateServlet.java) creates a new object from the other class 
> (UsersDB.java). When I compile UsersDB, everything is correct and the 
> .class archive is in the same path as the other .java archives. But 
> when I want to compile the SlateServlet.java archive it gives me 3 
> errors telling that it doesn't knows the class UsersDB when it tries 
> to create an object UserDB.
> What am I doing wrong? I've put the codes for this two java classes. 
> Thankyou
>
> ------------------------------------------------------------------------
> Tecnología, moda, motor, viajes,…suscríbete a nuestros boletines para 
> estar a la última MSN Newsletters 
> <http://newsletters.msn.com/hm/maintenanceeses.asp?L=ES&C=ES&P=WCMaintenance&Brand=WL&RU=http%3a%2f%2fmail.live.com>

>
> ------------------------------------------------------------------------
>
>
>
> import java.io.*;
> import javax.servlet.*;
> import javax.servlet.http.*;
>
> import java.util.Date;
>
> /**
>  * @author Jordi Forga
>  */
>
> public class SlateServlet extends HttpServlet
> {
>
>     public void init()
>     {
> 	ServletContext context = getServletContext();
> 	context.setAttribute("slate_text","");
> 	context.setAttribute("slate_user",null);
> 	context.setAttribute("slate_date",new Date());
> 	context.setAttribute("users_db",new UsersDB());
>     }
>
>
>     public void doGet(HttpServletRequest request, HttpServletResponse response)
>         throws IOException, ServletException
>     {
> 	process(request,response);
>     }
>
>     public void doPost(HttpServletRequest request, HttpServletResponse response)
>         throws IOException, ServletException
>     {
> 	process(request,response);
>     }
>
>
>     protected void process(HttpServletRequest request, HttpServletResponse response)
>         throws IOException, ServletException
>     {
> 	HttpSession oldSession = request.getSession(false);
> 	String sessionUser = null;
> 	if (oldSession != null) {
> 	    sessionUser = (String) oldSession.getAttribute("user");
> 	}
> 	String serv_path = request.getServletPath();
> 	if (serv_path.equals("/view.do")) {
> 	    view(response,sessionUser,null);
> 	} else if (serv_path.equals("/login.do")) {
> 	    String name = request.getParameter("name");
> 	    String passwd = request.getParameter("passwd");
> 	    ServletContext context = getServletContext();
> 	    UsersDB udb = (UsersDB)context.getAttribute("users_db");
> 	    if (udb.checkUser(name,passwd)) {
> 		request.getSession(true).setAttribute("user",name);
> 		view(response,name,null);
> 	    } else {
> 		view(response,sessionUser,"Error de autentificación");
> 	    }
> 	} else if (serv_path.equals("/logout.do")) {
> 	    request.getSession(true).invalidate();
> 	    view(response,null,null);
> 	} else if (serv_path.equals("/modify.do")) {
> 	    String message = request.getParameter("message");
> 	    if (sessionUser != null) {
> 		ServletContext context = getServletContext();
> 		context.setAttribute("slate_text",message);
> 		context.setAttribute("slate_user",sessionUser);
> 		context.setAttribute("slate_date",new Date());
> 		view(response,sessionUser,null);
> 	    } else {
> 		view(response,null,"Error: Debe autentificarse previamente");
> 	    }
> 	} else {
> 	    response.setContentType("text/plain");
> 	    PrintWriter wr = response.getWriter();
> 	    wr.println("Invalid path: "+serv_path);
> 	}
>     }
>     
>     
>     protected void view(HttpServletResponse response, String sessionUser, String errMsg)
>         throws IOException
>     {
> 	ServletContext context = getServletContext();
> 	String slateUser = (String) context.getAttribute("slate_user");
> 	String text = (String) context.getAttribute("slate_text");
> 	Date date = (Date) context.getAttribute("slate_date");
> 	String dateStr = date.toString();
>
> 	response.setContentType("text/html");
> 	PrintWriter wr = response.getWriter();
> 	wr.println("<HTML>");
> 	wr.println("<HEAD>");
> 	wr.println(" <META HTTP-EQUIV=\"Content-Type\" CONTENT=\"text/html; charset="+response.getCharacterEncoding()+"\">");
> 	wr.println(" <TITLE>Ejemplo de aplicaci&oacute;n con servlets</TITLE>");
> 	wr.println("</HEAD>");
> 	wr.println("<BODY BGCOLOR=\"lightblue\">");
> 	wr.println(" <center><H1>Ejemplo de aplicaci&oacute;n con servlets</H1></center>");
> 	wr.println(" <HR>");
> 	if (errMsg != null) {
> 	    wr.println(" <P><FONT COLOR=\"red\"><B><EM>"+errMsg+"</EM></B></FONT></P>");
> 	    wr.println(" <HR>");
> 	}
> 	if (sessionUser == null) {
> 	    wr.println(" <FORM METHOD=\"POST\" ACTION=\"login.do\"><CENTER>");
> 	    wr.println("  <P>Nombre de usuario:");
> 	    wr.println("  <INPUT TYPE=\"text\" NAME=\"name\" SIZE=\"10\"></P>");
> 	    wr.println("  <P>Clave de acceso:");
> 	    wr.println("  <INPUT TYPE=\"password\" NAME=\"passwd\" SIZE=\"10\"></P>");
> 	    wr.println("  <INPUT TYPE=\"submit\" NAME=\"login\" VALUE=\"Login\">");
> 	    wr.println(" </CENTER></FORM>");
> 	    wr.println(" <HR>");
> 	    if (slateUser == null) {
> 		wr.println(" <H3>Pizarra vacía</H3>");
> 	    } else {
> 		wr.println(" <H3>Pizarra modificada el d\u00eda <B>"+dateStr+
> 			"</B> por <B>"+slateUser+"</B>:</H3>");
> 		wr.println(" <DIV><PRE>");
> 		wr.println(text);
> 		wr.println("  </PRE></DIV>");
> 	    }
> 	} else {
> 	    wr.println(" <FORM METHOD=\"POST\" ACTION=\"logout.do\"><CENTER>");
> 	    wr.println("  <P><B>Usuario "+sessionUser+
> 			"</B>: <INPUT TYPE=\"submit\" NAME=\"logout\" VALUE=\"Logout\"></P>");
> 	    wr.println(" </CENTER></FORM>");
> 	    wr.println(" <HR>");
> 	    if (slateUser == null) {
> 		wr.println(" <H3>Pizarra vacía</H3>");
> 	    } else {
> 		wr.println(" <H3>Pizarra modificada el d\u00eda <B>"+dateStr+
> 			"</B> por <B>"+slateUser+"</B>:</H3>");
> 	    }
> 	    wr.println(" <FORM METHOD=\"POST\" ACTION=\"modify.do\"><CENTER>");
> 	    wr.println("  <TEXTAREA NAME=\"message\" ROWS=\"10\" COLS=\"60\">"+text+
> 			"</TEXTAREA><BR>");
> 	    wr.println("  <INPUT TYPE=\"reset\" VALUE=\"Restaura\">");
> 	    wr.println("  <INPUT TYPE=\"submit\" NAME=\"send\" VALUE=\"Canvia\">");
> 	    wr.println(" </CENTER></FORM>");
> 	}
> 	wr.println(" <HR>");
> 	wr.println(" <P><A HREF=\"index.html\">Descripci\u00f3n de la aplicaci\u00f3n</A></P>");
> 	wr.println("</BODY>");
> 	wr.println("</HTML>");
>     }
>
>
> }
>
>   
> ------------------------------------------------------------------------
>
>
>
>
>
> import java.util.Hashtable;
>
>
>
> /**
>
>  * @author Jordi Forga
>
>  */
>
>
>
>
>
> public class UsersDB
>
> {
>
>
>
>     public boolean checkUser(String name, String password)
>     {
> 	return name.length() >= 5 && name.equals(password);
>     }
>
>
> }
> ------------------------------------------------------------------------
>
> ---------------------------------------------------------------------
> To start a new topic, e-mail: users@tomcat.apache.org
> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: users-help@tomcat.apache.org


---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Mime
View raw message