Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

unable to compile class for jsp  RSS feed

 
santoo ujjire
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • 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
 
Ram Kumar Rengarajan
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi pop,

Which version Tomcat are you using now?. Pls Send ur java coding.
 
Tim Baker
Ranch Hand
Posts: 541
  • Mark post as helpful
  • send pies
  • 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
  • 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
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • 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.
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66144
143
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • 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
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!