stu ware

Greenhorn
+ Follow
since Feb 04, 2006
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by stu ware

Thanks. I got it.From this I understand that every class we develop should be in a package while using JSPs. Is that true.
18 years ago
JSP
Do I have to? I didnt place the class in any package. The class Counter.class is in directory classes.
18 years ago
JSP
Hi,

I am trying a simple jsp which is in the HFSJ.

My JSP file is BasicCounter.jsp

<html>
<body>
The page count is:
<%
out.println(Counter.getCount());
%>
</body>
</html>

My Counter.java file is
public class Counter
{
private static int count = 0;
public static synchronized int getCount()
{
count++;
return count;
}
}

The directory structure is like this.


webapps>exam>BasicCounter.jsp

webapps>exam>web-inf>classes>Counter.class

When I try to access the BasicCounter.jsp, I am getting the following exceptions.

exception

org.apache.jasper.JasperException: Unable to compile class for JSP

An error occurred at line: 4 in the jsp file: /BasicCounter.jsp
Generated servlet error:
Counter cannot be resolved


org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:510)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:375)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:314)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:264)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)

root cause

org.apache.jasper.JasperException: Unable to compile class for JSP

An error occurred at line: 4 in the jsp file: /BasicCounter.jsp
Generated servlet error:
Counter cannot be resolved


org.apache.jasper.compiler.DefaultErrorHandler.javacError(DefaultErrorHandler.java:84)
org.apache.jasper.compiler.ErrorDispatcher.javacError(ErrorDispatcher.java:328)
org.apache.jasper.compiler.JDTCompiler.generateClass(JDTCompiler.java:409)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:297)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:276)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:264)
org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:563)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:303)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:314)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:264)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)

note The full stack trace of the root cause is available in the Apache Tomcat/5.5.15 logs.

Any feedback is higly appreciated.

Thanks.
18 years ago
JSP
Hi,

I have created a jsp file hello.jsp and placed it in the directory "exam" under webapps. I am using tomcat.

There is nothing else in the "exam" directory apart from the hello.jsp file. I started the tomcat and tried to access the page as

http://localhost:8080/exam/hello.jsp

It didnt work. But when I created a web-inf directory and the subdirectories like classes, lib it worked.

What is the reason? Does executing the jsps need a directory structure.
18 years ago
JSP
Thanks for the reply.

I will do some coding before proceeding into jsps.

If you come across any resources of servlets which I can practice, please let me know.
Hi Everyone,

I am preparing for SCWCD and completed reading the first 6 chapters(i.e the servlets part) of HFSJ a couple of times.

Do I need to practice any servlet examples or can I go ahead and start with JSPs?

Does the reading alone is sufficient for the exam? I never developed any web applications using servlets. Do I need to practice writing some code? If so, please let me know about some resources.

Thanks.
Hey Merrill Higginson,

Awesome!!! You are right.

I wrote a sample test case with one html page and one servlet.

rootdit/first/hi.html is my html page.

Then I created a servlet by name "hi.html" and accessed it as

http://localhost:8080/first/hi.html


I got the output from the servlet instead of the html page.

I got my doubt clarified.

Thanks a lot to all of you.
18 years ago
Hey Merrill Higginson,

Awesome!!! You are right.

I wrote a sample test case with one html page and one servlet.

rootdit/first/hi.html is my html page.

Then I created a servlet by name "hi.html" and accessed it as

http://localhost:8080/first/hi.html


I got the output from the servlet instead of the html page.

I got my doubt clarified.

Thanks a lot to all of you.
18 years ago
Tested it before. Wondering how it was working!!!
18 years ago
Hi Ben Souther,

I know that it checks the web.xml file for servlet mapping. What I would like to know is....

Suppose the url is

http://localhost:8080/hello/javaranch.html

The container recognizes that the request is for a html page.

If the request is for http://localhost:8080/hello/javaranch.jsp, the container recognizes that the request is for a jsp page.

But if the url is http://localhost:8080/hello/javaranch how does the container know that the request is for a servlet. There is nothing in the url that suggests the container to look into the web.xml file to find the mapping.

I hope I am clear.

Thanks.
18 years ago
Hi,

Can someone tell me how a container recognizes that the incoming request is for a servlet?

Say http://localhost:8080/hello/javaranch

Here "javaranch" is the servlet class in hello directory. How does the container recognizes that javaranch is a servlet name and then checks the web.xml for the servlet class? There can be other html pages or jsps in hello directory.

So, does it check in the order of html page, jsps and then servlets or is there some thing else which I am missing?

Thanks.
18 years ago
Hi Bimal Patel,

Actually I was wrong. It worked when I placed my directory in webapps. I should have used webapps for my web application.

By the way, how to debug the servlets. Heard about log files. Where can I find them?

Any other techniques to debug......

Thanks for your help.
18 years ago
But when I created a directory at the same level as roots under webapps,

like rootdir/webapps/first/index.html

I am unable to access the index.html page as http://localhost:8080/first/index.html

I think http://localhost:8080/ is mapped to rootdir/webapps/root.

Nothing is working. It is so frustrating . Is there any way to findout what is going wrong. I dont think the container is able to read the web.xml file.

Any help is highly appreciated.
18 years ago
Hi,

I am trying to execute a simple Servlet but I am getting a "Requested Resource Not Available Error".

What I did was,

Installed tomcat 5.5.15 and set the java_home and catalina_home respectively to jdk and tomcat directories.

Developed a html page and dropped it in rootdir/webapps/root/first

Accessed it as, http://localhost:8080/first/index.html

I got the html output. So I assumed tomcat is working fine.

Later I wrote a sample servlet class, by name Hello.java and successfully compiled it. Placed it in rootdir/webapps/root/first/WEB-INF/classes directory.

Later, I wrote the web.xml file and deployed it in

rootdir/webapps/root/first/WEB-INF.

<web-app>
<servlet>
<servlet-name>HelloWorld</servlet-name>
<servlet-class>Hello</servlet-class>
</servlet>

<servlet-mapping>
<servlet-name>HelloWorld</servlet-name>
<url-pattern>/hithere</url-pattern>
</servlet-mapping>
</web-app>

I tried to access it as http://localhost:8080/first/hithere

But it was not working and I got a requested resource not available error.

Is there anyway to debug my application. Everything seems to be right. This is driving me crazy.

Any input will be highly appreciated.

Thanks.
18 years ago
Hi,

I am preparing for SCWCD. To test my sample servlets and JSPs I want to install Eclipse so that I can learn both together. I have never used Eclipse before.

Can anyone suggest me any tutorial or how to run servlets and jsps in Eclipse. Do we need to install tomcat for this purpose?

Or should I start learning eclispse with small java programs?

Thanks.