You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Michael Echavez <mi...@gmail.com> on 2005/06/08 16:58:19 UTC
tomcat causes servlet malfunction???
Hi Everyone!
There is a servlet i found from a book that utilizes the parameters from
servlets but whenever i run it the browser doesnt seem to open the class
properly and instead it only downloads the .class file. I think the problem
here has something to do with the new Tomcat version. Can someone try
deploying the application so that I'll be able to find out whether what the
problem really is. Below are the codes i used:
the code below is for Form.html where i have to enter the information that
will be passed onto the servlet:
<HTML>
<HEAD>
<TITLE>
Parameter Servlet Form
</TITLE>
</HEAD>
<BODY>
<form
action="servlet/chapter2.ParameterServlet"
method=POST>
<table width="400" border="0" cellspacing="0">
<tr>
<td>Name: </td>
<td>
<input type="text"
name="name"
size="20"
maxlength="20"
</td>
<td>SSN:</td>
<td>
<input type="text" name="ssn" size="11" maxlength="11">
</td>
</tr>
<tr>
<td>Age:</td>
<td>
<input type="text" name="age" size="3" maxlength="3">
</td>
<td>email:</td>
<td>
<input type="text"
name="email"
size="30"
maxlength="30">
</td>
</tr>
<tr>
<td> </td>
<td> </td>
<td> </td>
<td>
<input type="submit" name="Submit" value="Submit">
<input type="reset" name="Reset" value="Reset">
</td>
</tr>
</table>
</FORM>
</BODY>
</HTML>
and here is the code for ParamterServlet.java:
package chapter2;
import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
import java.util.*;
public class ParameterServlet extends HttpServlet {
public void init(ServletConfig config) throws ServletException {
// Always pas the ServletConfig object to the super class
super.init(config);
}
// Process the HTTP Get request
public void doGet (HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
doPost(request, response);
}
// Process the HTTP Post request
public void doPost (HttpServletRequest request, HttpServletResponse
response) throws ServletException, IOException {
response.setContentType("html/text");
PrintWriter out = response.getWriter();
out.println("<html>");
out.println("<head>");
out.println("<title>Parameter Servlet</title>");
out.println("</head>");
out.println("<body>");
// Get an enumeration of the parameter names
Enumeration parameters = request.getParameterNames();
String param = null;
// Iterate over the parameter names,
// getting the parameters values
while(parameters.hasMoreElements()) {
param = (String)parameters.nextElement();
out.println(param + " : " + request.getParameter(param) + "<BR>");
}
out.println("</body></html>");
out.close();
}
}
Thank you and Good day!
Regards,
michael
Re: tomcat causes servlet malfunction???
Posted by Jason Bainbridge <jb...@gmail.com>.
On 6/8/05, Michael Echavez <mi...@gmail.com> wrote:
> Hi Everyone!
> There is a servlet i found from a book that utilizes the parameters from
> servlets but whenever i run it the browser doesnt seem to open the class
> properly and instead it only downloads the .class file. I think the problem
> here has something to do with the new Tomcat version. Can someone try
> deploying the application so that I'll be able to find out whether what the
> problem really is. Below are the codes i used:
That is using the ancient /servlet directory default servlet thingy,
the class you have needs to be packaged and then placed in
%TOMCAT_HOME%/webapps/yourwebapp/WEB-INF/classes for it to work
properly.
Regards,
--
Jason Bainbridge
http://kde.org - webmaster@kde.org
Personal Site - http://jasonbainbridge.com
---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-user-help@jakarta.apache.org
Re: tomcat causes servlet malfunction???
Posted by Michael Echavez <mi...@gmail.com>.
it is located in the "\web\WEB-INF\classes\chapter2" directory.
On 6/9/05, Ben Souther <bs...@fwdco.com> wrote:
>
> Where is the servlet's class file?
>
>
> On Wed, 2005-06-08 at 11:35, Michael Echavez wrote:
> > i didnt use the invoker here. ive explicitly mapped my servlet with
> > that url. below is a part of my web.xml
> >
> > <servlet>
> > <servlet-name>ParameterServlet</servlet-name>
> > <description>
> > This servlet retrieves the parameters sent to it and returns
> > the parameters and their values back to the client.
> > </description>
> > <servlet-class>chapter2.ParameterServlet</servlet-class>
> > <!-- Load this servlet at server startup time -->
> > <load-on-startup>5</load-on-startup>
> > </servlet>
> >
> > <servlet-mapping>
> > <servlet-name>ParameterServlet</servlet-name>
> > <url-pattern>/servlet/chapter2.ParameterServlet</url-pattern>
> > </servlet-mapping>
> >
> > I actually thought that there was some kind of an agreement to use
> > "/servlet" for servlet urls. Thank you for the links. I actually
> > learned a lot from them.
> >
> > Yes, the browser does download the file. it says that it has found a
> > PARAMETERSERVLET file since the url is
> > ...\servlet\chapter2.ParameterServlet
> > It actually thinks that ParameterServlet is an extension. I'm really
> > lost now cause i have a couple of other servlets that is in the same
> > directory and they work properly. this is the only one that doesnt.
> >
> > On 6/8/05, Ben Souther <bs...@fwdco.com> wrote:
> > If the browser can see the .class file and download it, then
> > it's not in
> > the right place.
> >
> > Also: action="servlet/chapter2.ParameterServlet"
> > The "servlet/" section in the URL is an outdated way of
> > invoking a
> > servlet. It uses the deprecated (and disabled in current
> > versions of
> > Tocmat) Invoker servlet.
> >
> > You will need to map your servlets in web.xml or disable the
> > invoker in
> > order to run them.
> >
> > On the InvokerServlet:
> > http://jakarta.apache.org/tomcat/faq/misc.html#evil
> > http://faq.javaranch.com/view?InvokerServlet
> >
> >
> > On Wed, 2005-06-08 at 11:10, Michael Echavez wrote:
> > > Hi Ben,
> > > It is so nice of you to respond so quickly.
> > > Actually, I've already deployed a few simple servlets
> > already and I am
> > > sure that the .class file for the servlet is in the right
> > directory. I
> > > was just wasnt sure why tomcat couldnt load the class file
> > correctly.
> > > Also, I already read the tomcat documentation you pointed me
> > to before
> > > i posted my question.
> > > I really appreciate the link with the example applications.
> > I think it
> > > will help me a lot with practicing on servlets, jsps and
> > beans. Again,
> > > Thank you so much!
> > > Regards,
> > > Michael
> > >
> > > On 6/8/05, Ben Souther <bs...@fwdco.com> wrote:
> > > Michael,
> > >
> > > Have a look at the documentation for classloading in
> > TC to
> > > find out
> > > where your class files need to go.
> > >
> > http://jakarta.apache.org/tomcat/tomcat-5.5-doc/class-loader-howto.html
> > >
> > > You'll also need to map your servlet in your web.xml
> > file.
> > >
> > >
> > > I have some example applications that are packaged
> > as war
> > > files that you
> > > can use as a reference if you like:
> > > http://simple.souther.us.
> > >
> > > -Ben
> > >
> > >
> > >
> > > On Wed, 2005-06-08 at 10:58, Michael Echavez wrote:
> > > > Hi Everyone!
> > > > There is a servlet i found from a book that
> > utilizes the
> > > parameters from
> > > > servlets but whenever i run it the browser doesnt
> > seem to
> > > open the class
> > > > properly and instead it only downloads the .class
> > file. I
> > > think the problem
> > > > here has something to do with the new Tomcat
> > version. Can
> > > someone try
> > > > deploying the application so that I'll be able to
> > find out
> > > whether what the
> > > > problem really is. Below are the codes i used:
> > > >
> > > > the code below is for Form.html where i have to
> > enter the
> > > information that
> > > > will be passed onto the servlet:
> > > > <HTML>
> > > > <HEAD>
> > > > <TITLE>
> > > > Parameter Servlet Form
> > > > </TITLE>
> > > > </HEAD>
> > > > <BODY>
> > > >
> > > > <form
> > > > action="servlet/chapter2.ParameterServlet"
> > > > method=POST>
> > > > <table width="400" border="0" cellspacing="0">
> > > > <tr>
> > > > <td>Name: </td>
> > > > <td>
> > > > <input type="text"
> > > > name="name"
> > > > size="20"
> > > > maxlength="20"
> > > > </td>
> > > > <td>SSN:</td>
> > > > <td>
> > > > <input type="text" name="ssn" size="11"
> > maxlength="11">
> > > > </td>
> > > > </tr>
> > > > <tr>
> > > > <td>Age:</td>
> > > > <td>
> > > > <input type="text" name="age" size="3"
> > maxlength="3">
> > > > </td>
> > > > <td>email:</td>
> > > > <td>
> > > > <input type="text"
> > > > name="email"
> > > > size="30"
> > > > maxlength="30">
> > > > </td>
> > > > </tr>
> > > > <tr>
> > > > <td> </td>
> > > > <td> </td>
> > > > <td> </td>
> > > > <td>
> > > > <input type="submit" name="Submit" value="Submit">
> > > > <input type="reset" name="Reset" value="Reset">
> > > > </td>
> > > > </tr>
> > > > </table>
> > > > </FORM>
> > > >
> > > > </BODY>
> > > > </HTML>
> > > >
> > > > and here is the code for ParamterServlet.java:
> > > > package chapter2;
> > > >
> > > > import javax.servlet.*;
> > > > import javax.servlet.http.*;
> > > > import java.io.*;
> > > > import java.util.*;
> > > >
> > > > public class ParameterServlet extends HttpServlet
> > {
> > > >
> > > > public void init(ServletConfig config) throws
> > > ServletException {
> > > > // Always pas the ServletConfig object to the
> > super class
> > > > super.init (config);
> > > > }
> > > >
> > > > // Process the HTTP Get request
> > > > public void doGet (HttpServletRequest request,
> > > HttpServletResponse response)
> > > > throws ServletException, IOException {
> > > > doPost(request, response);
> > > > }
> > > >
> > > > // Process the HTTP Post request
> > > > public void doPost (HttpServletRequest request,
> > > HttpServletResponse
> > > > response) throws ServletException, IOException {
> > > > response.setContentType ("html/text");
> > > > PrintWriter out = response.getWriter();
> > > >
> > > > out.println("<html>");
> > > > out.println("<head>");
> > > > out.println("<title>Parameter Servlet</title>");
> > > > out.println("</head>");
> > > > out.println ("<body>");
> > > >
> > > > // Get an enumeration of the parameter names
> > > > Enumeration parameters =
> > request.getParameterNames();
> > > >
> > > > String param = null;
> > > >
> > > > // Iterate over the parameter names,
> > > > // getting the parameters values
> > > > while(parameters.hasMoreElements()) {
> > > > param = (String)parameters.nextElement();
> > > > out.println(param + " : " +
> > request.getParameter(param) +
> > > "<BR>");
> > > > }
> > > >
> > > > out.println("</body></html>");
> > > > out.close();
> > > > }
> > > > }
> > > >
> > > > Thank you and Good day!
> > > > Regards,
> > > > michael
> > >
> > >
> >
> >
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: tomcat-user-help@jakarta.apache.org
>
>
Re: tomcat causes servlet malfunction???
Posted by Ben Souther <bs...@fwdco.com>.
Where is the servlet's class file?
On Wed, 2005-06-08 at 11:35, Michael Echavez wrote:
> i didnt use the invoker here. ive explicitly mapped my servlet with
> that url. below is a part of my web.xml
>
> <servlet>
> <servlet-name>ParameterServlet</servlet-name>
> <description>
> This servlet retrieves the parameters sent to it and returns
> the parameters and their values back to the client.
> </description>
> <servlet-class>chapter2.ParameterServlet</servlet-class>
> <!-- Load this servlet at server startup time -->
> <load-on-startup>5</load-on-startup>
> </servlet>
>
> <servlet-mapping>
> <servlet-name>ParameterServlet</servlet-name>
> <url-pattern>/servlet/chapter2.ParameterServlet</url-pattern>
> </servlet-mapping>
>
> I actually thought that there was some kind of an agreement to use
> "/servlet" for servlet urls. Thank you for the links. I actually
> learned a lot from them.
>
> Yes, the browser does download the file. it says that it has found a
> PARAMETERSERVLET file since the url is
> ...\servlet\chapter2.ParameterServlet
> It actually thinks that ParameterServlet is an extension. I'm really
> lost now cause i have a couple of other servlets that is in the same
> directory and they work properly. this is the only one that doesnt.
>
> On 6/8/05, Ben Souther <bs...@fwdco.com> wrote:
> If the browser can see the .class file and download it, then
> it's not in
> the right place.
>
> Also: action="servlet/chapter2.ParameterServlet"
> The "servlet/" section in the URL is an outdated way of
> invoking a
> servlet. It uses the deprecated (and disabled in current
> versions of
> Tocmat) Invoker servlet.
>
> You will need to map your servlets in web.xml or disable the
> invoker in
> order to run them.
>
> On the InvokerServlet:
> http://jakarta.apache.org/tomcat/faq/misc.html#evil
> http://faq.javaranch.com/view?InvokerServlet
>
>
> On Wed, 2005-06-08 at 11:10, Michael Echavez wrote:
> > Hi Ben,
> > It is so nice of you to respond so quickly.
> > Actually, I've already deployed a few simple servlets
> already and I am
> > sure that the .class file for the servlet is in the right
> directory. I
> > was just wasnt sure why tomcat couldnt load the class file
> correctly.
> > Also, I already read the tomcat documentation you pointed me
> to before
> > i posted my question.
> > I really appreciate the link with the example applications.
> I think it
> > will help me a lot with practicing on servlets, jsps and
> beans. Again,
> > Thank you so much!
> > Regards,
> > Michael
> >
> > On 6/8/05, Ben Souther <bs...@fwdco.com> wrote:
> > Michael,
> >
> > Have a look at the documentation for classloading in
> TC to
> > find out
> > where your class files need to go.
> >
> http://jakarta.apache.org/tomcat/tomcat-5.5-doc/class-loader-howto.html
> >
> > You'll also need to map your servlet in your web.xml
> file.
> >
> >
> > I have some example applications that are packaged
> as war
> > files that you
> > can use as a reference if you like:
> > http://simple.souther.us.
> >
> > -Ben
> >
> >
> >
> > On Wed, 2005-06-08 at 10:58, Michael Echavez wrote:
> > > Hi Everyone!
> > > There is a servlet i found from a book that
> utilizes the
> > parameters from
> > > servlets but whenever i run it the browser doesnt
> seem to
> > open the class
> > > properly and instead it only downloads the .class
> file. I
> > think the problem
> > > here has something to do with the new Tomcat
> version. Can
> > someone try
> > > deploying the application so that I'll be able to
> find out
> > whether what the
> > > problem really is. Below are the codes i used:
> > >
> > > the code below is for Form.html where i have to
> enter the
> > information that
> > > will be passed onto the servlet:
> > > <HTML>
> > > <HEAD>
> > > <TITLE>
> > > Parameter Servlet Form
> > > </TITLE>
> > > </HEAD>
> > > <BODY>
> > >
> > > <form
> > > action="servlet/chapter2.ParameterServlet"
> > > method=POST>
> > > <table width="400" border="0" cellspacing="0">
> > > <tr>
> > > <td>Name: </td>
> > > <td>
> > > <input type="text"
> > > name="name"
> > > size="20"
> > > maxlength="20"
> > > </td>
> > > <td>SSN:</td>
> > > <td>
> > > <input type="text" name="ssn" size="11"
> maxlength="11">
> > > </td>
> > > </tr>
> > > <tr>
> > > <td>Age:</td>
> > > <td>
> > > <input type="text" name="age" size="3"
> maxlength="3">
> > > </td>
> > > <td>email:</td>
> > > <td>
> > > <input type="text"
> > > name="email"
> > > size="30"
> > > maxlength="30">
> > > </td>
> > > </tr>
> > > <tr>
> > > <td> </td>
> > > <td> </td>
> > > <td> </td>
> > > <td>
> > > <input type="submit" name="Submit" value="Submit">
> > > <input type="reset" name="Reset" value="Reset">
> > > </td>
> > > </tr>
> > > </table>
> > > </FORM>
> > >
> > > </BODY>
> > > </HTML>
> > >
> > > and here is the code for ParamterServlet.java:
> > > package chapter2;
> > >
> > > import javax.servlet.*;
> > > import javax.servlet.http.*;
> > > import java.io.*;
> > > import java.util.*;
> > >
> > > public class ParameterServlet extends HttpServlet
> {
> > >
> > > public void init(ServletConfig config) throws
> > ServletException {
> > > // Always pas the ServletConfig object to the
> super class
> > > super.init (config);
> > > }
> > >
> > > // Process the HTTP Get request
> > > public void doGet (HttpServletRequest request,
> > HttpServletResponse response)
> > > throws ServletException, IOException {
> > > doPost(request, response);
> > > }
> > >
> > > // Process the HTTP Post request
> > > public void doPost (HttpServletRequest request,
> > HttpServletResponse
> > > response) throws ServletException, IOException {
> > > response.setContentType ("html/text");
> > > PrintWriter out = response.getWriter();
> > >
> > > out.println("<html>");
> > > out.println("<head>");
> > > out.println("<title>Parameter Servlet</title>");
> > > out.println("</head>");
> > > out.println ("<body>");
> > >
> > > // Get an enumeration of the parameter names
> > > Enumeration parameters =
> request.getParameterNames();
> > >
> > > String param = null;
> > >
> > > // Iterate over the parameter names,
> > > // getting the parameters values
> > > while(parameters.hasMoreElements()) {
> > > param = (String)parameters.nextElement();
> > > out.println(param + " : " +
> request.getParameter(param) +
> > "<BR>");
> > > }
> > >
> > > out.println("</body></html>");
> > > out.close();
> > > }
> > > }
> > >
> > > Thank you and Good day!
> > > Regards,
> > > michael
> >
> >
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-user-help@jakarta.apache.org