requestparams

[nobr]Hi all, i am still very new after a few attempt on JSP. I trying to do a java and compile it to class. Then try to access it without the physical file.

I have used the sample code from the apache tomcat on RequestParamExample and try to implement it for my webpage.

It seems to able to compile successfully. However, I ran into problem as it gives me the following error msg... Please also take a look at my java code.

Error Message:

java.util.MissingResourceException: Can't find resource for bundle java.util.PropertyResourceBundle, key requestparams.menu1

java.util.ResourceBundle.getObject(Unknown Source)

java.util.ResourceBundle.getObject(Unknown Source)

java.util.ResourceBundle.getString(Unknown Source)

christ.doGet(christ.java:94)

javax.servlet.http.HttpServlet.service(HttpServlet.java:689)

javax.servlet.http.HttpServlet.service(HttpServlet.java:802)

filters.ExampleFilter.doFilter(ExampleFilter.java:101)

Code as following:

import java.io.*;

import java.text.*;

import java.util.*;

import javax.servlet.*;

import javax.servlet.http.*;

import util.HTMLFilter;

/**

* Example servlet showing request headers

*

* @author James Duncan Davidson <duncan@eng.sun.com>

*/

publicclass christextends HttpServlet{

ResourceBundle rb = ResourceBundle.getBundle("LocalStrings");

publicvoid doGet(HttpServletRequest request,

HttpServletResponse response)

throws IOException, ServletException

{

response.setContentType("text/html");

PrintWriter out = response.getWriter();

out.println("<html>");

out.println("<body>");

out.println("<head>");

String title = rb.getString("requestparams.title");

out.println("<title>" + title +"</title>");

out.println("<link href=\"../style.css\" rel=\"stylesheet\" type=\"text/css\">");

out.println("</head>");

out.println("<body bgcolor=\"#333333\" leftmargin=0 topmargin=0 bottommargin=0>");

// img stuff not req'd for source code html showing

// all links relative

String menu1 = request.getParameter("menu1");

out.println(rb.getString("requestparams.params-in-req") +"<br>");

if (menu1 !=null){

out.println(rb.getString("requestparams.menu1"));

out.println(" = " + HTMLFilter.filter(menu1) +"<br>");

}else{

out.println(rb.getString("requestparams.no-params"));

}

out.println("<P>");

out.println("<form action=christ method=POST>");

out.println("<table width=900 border=0 cellpadding=0 cellspacing=0 bgcolor=\"#000000\" background=\"../images/bg_camera.jpg\" style=\"background-repeat: no-repeat\">");

out.println("<tr><td width=247 height=96> </td><td width=653> </td></tr><tr><td height=718> </td><td valign=\"top\"><table width=100% border=0 cellpadding=0 cellspacing=0><tr>");

out.println("<td width=653 height=404 valign=\"top\">

<span class=\"header\">Buying Guide: Features Search</span>");

out.println("<br><br>");

out.println("<span class=\"bodytext\">Cost of Camera: </span>");

///////////////////////////////////////////////////////////////////////////////////////

out.println(rb.getString("requestparams.menu1"));

///////////////////////////////////////////////////////////////////////////////////////

out.println("<select name=menu1>");

out.println("<option selected>?$500</option>");

out.println("<option>$501-$1000</option>");

out.println("<option>$1001-$1500</option>");

out.println("</select>");

out.println("

");

out.println("<input type=submit>");

out.println("

</td></tr><tr><td height=314> </td></tr></table>");

out.println("</td></tr><tr><td height=86> </td><td> </td></tr></table>");

out.println("</form>");

out.println("</body>");

out.println("</html>");

}

publicvoid doPost(HttpServletRequest request,

HttpServletResponse response)

throws IOException, ServletException

{

doGet(request, response);

}

}

if i remove a single line of code from the java class...

out.println(rb.getString("requestparams.menu1"));

then the url will be displayed. However, the button still won't work. And it will throw such error msg:

java.util.MissingResourceException: Can't find resource for bundle java.util.PropertyResourceBundle, key requestparams.menu1

java.util.ResourceBundle.getObject(Unknown Source)

java.util.ResourceBundle.getObject(Unknown Source)

java.util.ResourceBundle.getString(Unknown Source)

christ.doGet(christ.java:64)

christ.doPost(christ.java:101)

javax.servlet.http.HttpServlet.service(HttpServlet.java:709)

javax.servlet.http.HttpServlet.service(HttpServlet.java:802)

filters.ExampleFilter.doFilter(ExampleFilter.java:101)

Thanks for all the help...

LostBoy.

Message was edited by:

diskhub[/nobr]

[7417 byte] By [diskhuba] at [2007-11-26 18:16:28]
# 1

Hello,

From the error it seems it is missing the required resource bundle class.

[b]ResourceBundle rb = ResourceBundle.getBundle("LocalStrings");[/b]

import that particular class and it should work fine.

[b]import java.util.ResourceBundle......[/b]

Let me know.

kris10a at 2007-7-9 5:50:03 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 2
is this the right way to handle form element such as the <select name="menu1">.... with this following method:out.println(rb.getString("requestparams.menu1"));please advice...is it a returned string or array?
diskhuba at 2007-7-9 5:50:03 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...