• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Liutauras Vilda
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Saloon Keepers:
  • Scott Selikoff
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
  • Frits Walraven
Bartenders:
  • Stephan van Hulst
  • Carey Brown

unable to compile class for jsp

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hello ppl,

i am new to jsp. i have one error saying unable to compile class for jsp.

i have one .html, one .jsp( containing beans) and .java(kept in web-inf folder).

i think i have problem in .jsp file. i am posting please read it and tell me the problem.

.jsp file

<jsp:useBean id="languageBean" scope="page" class="LanguageBean">
<jsp:setProperty name="languageBean" property="*" />
</jsp:useBean>

<html>
<body>

<P>Hello, <jsp:getProperty name="languageBean" property="name"/></p>

<P>your favourite language is
<jsp:getProperty name="languageBean" property="language"/></p>

<p>my comments on this language is
<jsp:getProperty name="languageBean" property="languageComments"/></p>
</body>
</html>



do we need to specify something in classpath. pls read it and give suggestions.

Thanks,
pop
 
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi pop,

Which version Tomcat are you using now?. Pls Send ur java coding.
 
Ranch Hand
Posts: 541
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Firstly we need to see what the error is, when it says it can't compile the JSP, it always tells you why.

Secondly, you need to put .class files in your WEB-INF/classes folder and not .java files. You need to compile your .java files into .class files.
 
santoo ujjire
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi,

this is my .jsp file.

<jsp:useBean id="languageBean" scope="page" class="LanguageBean.class">
<jsp:setProperty name="languageBean" property="*" />
</jsp:useBean>

<html>
<body>

<P>Hello, <jsp:getProperty name="languageBean" property="name"/></p>

<P>your favourite language is
<jsp:getProperty name="languageBean" property="language"/></p>

<p>my comments on this language is
<jsp:getProperty name="languageBean" property="languageComments"/></p>
</body>
</html>


this is .html file.

<html>
<body>
<form method="post" action="beans.jsp">
please enter your username :
<input type="text" name="name">
what is your favourite language?
<select name="language">
<option value="Java">Java
<option value="C++">C++
<option value="Perl">Perl
</select>
<input type="submit" value="submit button">
</form>
</body>
</html>


this is .java file

public class LanguageBean{
private String name;
private String language;

public LanguageBean(){}

public void setName(String name){
this.name=name;
}

public String getName(){
return name;
}

public void setLanguage(String language){
this.language=language;
}

public String getLanguage(){
return language;}

public String getLanguageComments(){
if(language.equals("Java")) {
return "king of java";
}else if(language.equals("C++")){
return "king of c++";
}else if(language.equals("Perl")){
return "get bored";}
else return " i know little bit";
}
}

i compiled this .java file and put .class file in web-inf/classes directory.

i have tomcat structure as follows.

webapps
sub(application name)
beans.html, beans.jsp, web-inf
inside web-inf, classes, lib, web.xml.

the errror what i get is when i click http://localhost:8080/sub/beans.jsp is

unable to compile class for jsp.

cannot resolve symbol

class LanguageBean;


this is the problems pls read it and provide suggestions.

THanks,
pop
 
Sheriff
Posts: 13411
Firefox Browser VI Editor Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Without reading all of your code...
I can see one issue.

Your bean needs to be packaged.
Starting with j2sdk1.4.1, you can't import non packaged (default package) classes from packaged ones.
 
Sheriff
Posts: 67752
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
"santoo tr",

There aren't may rules that have been put into place here on the Ranch, but one that we take very seriously regards the use of proper names. Please take a look at the JavaRanch Naming Policy and adjust your display name to match it.

In particular, your display name must be a first and a last name separated by a space character, and must not be obviously fictitious.

Thanks!
bear
Forum Bartender
 
I didn't like the taste of tongue and it didn't like the taste of me. I will now try this tiny ad:
New web page for Paul's Rocket Mass Heaters movies
https://coderanch.com/t/785239/web-page-Paul-Rocket-Mass
reply
    Bookmark Topic Watch Topic
  • New Topic