Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Jsp import problem  RSS feed

 
sridhar lakka
Ranch Hand
Posts: 109
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,
I am facing the following problem please help me,

I have a normal class and there I set some value and I am trying to get that value in JSP.
This class not under any package.

Class code:

public class X {
public static void main(String [] args)
{
String getTable = getTable();
System.out.println("This is "+getTable);
}
public static String getTable()
{
boolean secFlag=true;
boolean secSubFlag=true;
String sec1 ="Section1 - MTTR";
String subSec1 = "Sub Section1 - MTTR (110)";
if (secFlag)
{
return "<table" + "\"" + " width=\"100%\">" + "<tr><td>" + sec1 + "</td></tr>";
}
if (secSubFlag)
{
return "<tr><td>" + subSec1 + "</td></tr></table>";
}
return null;
}
}

Jsp code:

<%@ page language="java"%>
<%@ page import = "X" %>
<%
String getTable = X.getTable();
%>
<html>
<head><body>Hello this is <br>
<%= getTable%>
</body></head>
<%
out.println("Sreedhar");
%>
</html>


I am facing problem while import.

Regards,
Sree
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65826
134
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by sridhar lakka:
This class not under any package.

That's your problem. Your class must be packaged. See the JSP FAQ for details.
 
sridhar lakka
Ranch Hand
Posts: 109
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I know that is my problem , but can we import a class without package into JSP.
Please have a look at http://www.thescripts.com/forum/thread16713.html , they are using class directly dont how..

Regards
Sree
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Look at the FAQ mentioned by Bear. You can find them
here:
http://faq.javaranch.com/java/PackageYourBeans
and
http://faq.javaranch.com/java/BeansNotFound

Prior to JDK 1.4 Sun's compiler allowed the importing of classes in the default package (no package) from packaged classes; even though the spec prohibits it. In one of the 1.4 versions, they tightened this up to be more spec compliant.

It's always been a bad practice to use unpackaged classes in anything but trivial applications, now it is illegal and will blow up.

In short, you need to package your beans.
[ January 03, 2008: Message edited by: Ben Souther ]
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!