It looks like the problem is in one of the rb.getString calls. This is
where the servlet attempts to find a localized string to use by calling
the resource bundle.
One of the several ways that resource bundles can be made is to create a
class that extends the abstract ResourceBundle class. Basically it does
a key value lookup on the string you're looking for. The correct
resource bundle is dynamically choosen based either on the system locale
or on a hard coded local in the code. In this example the resource
bundle is called "LocalStrings". If the locale is German speaking
Switzerland, the system will look for LocalStrings_de_CH. If it doesn't
find the exact match, it backs off until it finds something it can use.
I'm guessing that there is a class called LocalStrings.class in one of
the jar files distributed with the JSWDK (I haven't taken a look through
the jar files myself). It looks like the class is found, but then one of
the strings you are requesting isn't in the resource bundle.
There are a couple of ways around this problem. The easiest is to hard
code the strings into the servlet. Of course this defeats the whole
purpose of writing your code so that it can be localized. If all you are
trying to do is learn about servlets and JSP, then this is the way to
go. The second way is to write your own resource bundle that has the
strings you need in it.
On final note on resource bundles. They don't have to be created as
class files. They can also be text files that are read when the bundle
is requested. I prefer that system because it doesn't require a coder
and a recompile to do the localization, but it still needs someone with
some skill to make sure that it all turns out alright.
Carles
Wade Hovind wrote:
>
> Let me try a slightly different tack....
>
> When I try to access a servlet based almost solely on the session example I
> get the following. I've never dealt with resources in my limited Java
> experience. I don't expect the answer per se but a gentle nudge (or kick in
> the butt) in the proper direction would be greatly appreciated.
>
> > Error: 500
> > Internal Servlet Error:
> >
> > java.util.MissingResourceException: Can't find resource
> > at java.util.ResourceBundle.getObject(Compiled Code)
> > at java.util.ResourceBundle.getString(ResourceBundle.java:258)
> > at Authenticate.doGet(Compiled Code)
> > at javax.servlet.http.HttpServlet.service(HttpServlet.java:715)
> > at javax.servlet.http.HttpServlet.service(HttpServlet.java:840)
> > at
> > com.sun.web.core.ServletWrapper.handleRequest(ServletWrapper.java:154)
> > at
> > com.sun.web.core.InvokerServlet.service(InvokerServlet.java:168)
> > at javax.servlet.http.HttpServlet.service(HttpServlet.java:840)
> > at
> > com.sun.web.core.ServletWrapper.handleRequest(ServletWrapper.java:154)
> > at com.sun.web.core.Context.handleRequest(Context.java:412)
> > at com.sun.web.server.ConnectionHandler.run(Compiled Code)
> >
> > The code that refers to the resource is identical to the examples that
> > I've
> > looked at. I'm using the following platform etc.
> >
> > Windows NT (sp4)
> > VAJ TEch Preview Java 2 SDK
> > Java Server Web Dev Kit Version 1.0 EA
> >
> >
> > I greatly appreciate any help offered,
> > Wade Hovind
> > [EMAIL PROTECTED]
> >
> >
> > Source Code Follows:
> >
> > import java.io.*;
> > import java.text.*;
> > import java.util.*;
> > import javax.servlet.*;
> > import javax.servlet.http.*;
> >
> >
> > public class Authenticate extends HttpServlet {
> >
> > ResourceBundle rb = ResourceBundle.getBundle("LocalStrings");
> >
> > /**
> > * Insert the method's description here.
> > * Creation date: (6/27/99 10:39:09 AM)
> > * @param request javax.servlet.http.HttpServletRequest
> > * @param response javax.servlet.http.HttpServletResponse
> > * @exception javax.servlet.ServletException The exception description.
> > * @exception java.io.IOException The exception description.
> > */
> > public void doGet(HttpServletRequest request, HttpServletResponse
> > response)
> > throws javax.servlet.ServletException, java.io.IOException {
> > response.setContentType("text/html");
> > PrintWriter out = response.getWriter();
> > out.println("<html>");
> > out.println("<body bgcolor=\"white\">");
> > out.println("<head>");
> > String title = rb.getString("sessions.title");
> > out.println("<title>" + title + "</title>");
> > out.println("</head>");
> > out.println("<body>");
> > //out.println("<H2>Working!</H2>");
> >
> > HttpSession session = request.getSession();
> > out.println(rb.getString("sessions.id") + " " + session.getId());
> > out.println("<br>");
> > out.println(rb.getString("sessions.created") + " ");
> > out.println(new Date(session.getCreationTime()) + "<br>");
> > out.println(rb.getString("sessions.lastaccessed") + " ");
> > out.println(new Date(session.getLastAccessedTime()));
> > String username = request.getParameter("username");
> > String password = request.getParameter("password");
> > if (username != null && password != null) {
> > session.putValue(username, password);
> > }
> > int usernameIndex = -1;
> > int passwordIndex = -1;
> > String[] valueNames = session.getValueNames();
> > if (valueNames != null && valueNames.length > 0) {
> > for (int i = 0; i < valueNames.length; i++) {
> > String name = valueNames[i];
> > String value = session.getValue(name).toString();
> > if (name == "username") {
> > usernameIndex = i;
> > }
> > if (name == "password" && usernameIndex != -1) {
> > passwordIndex = i;
> > }
> > }
> > if (usernameIndex != -1 && passwordIndex != -1) {
> >
> > out.println(session.getValue(valueNames[usernameIndex]).toString() + " is
> > authenticated <BR>");
> >
> > out.println(session.getValue(valueNames[passwordIndex]).toString() + " was
> > the password <BR>");
> > } else {
> > out.println("Not authenticated");
> > }
> > }
> > out.println("<P>");
> > out.print("<form action=\"");
> > out.print("SessionExample\" ");
> > out.println("method=POST>");
> > out.println(rb.getString("Username"));
> > out.println("<input type=text size=20 name=username>");
> > out.println("<br>");
> > out.println(rb.getString("Password"));
> > out.println("<input type=password size=20 name=password>");
> > out.println("<br>");
> > out.println("<input type=submit>");
> > out.println("</form>");
> > out.println("</body>");
> > out.println("</html>");
> > }
> > /**
> > * Insert the method's description here.
> > * Creation date: (6/27/99 10:41:35 AM)
> > * @param request javax.servlet.http.HttpServletRequest
> > * @param response javax.servlet.http.HttpServletResponse
> > * @exception javax.servlet.ServletException The exception description.
> > * @exception java.io.IOException The exception description.
> > */
> > public void doPost(HttpServletRequest request, HttpServletResponse
> > response)
> >
> > throws javax.servlet.ServletException, java.io.IOException
> > {
> > doGet(request, response);
> > }
> > }
> >
> > ==========================================================================
> > =
> > To unsubscribe, send email to [EMAIL PROTECTED] and include in the
> > body
> > of the message "signoff JSP-INTEREST". For general help, send email to
> > [EMAIL PROTECTED] and include in the body of the message "help".
>
> ===========================================================================
> To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
> of the message "signoff JSP-INTEREST". For general help, send email to
> [EMAIL PROTECTED] and include in the body of the message "help".
===========================================================================
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff JSP-INTEREST". For general help, send email to
[EMAIL PROTECTED] and include in the body of the message "help".