aspose file tools*
The moose likes Servlets and the fly likes HELP HELP !!! JSP-BEAN Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "HELP HELP !!! JSP-BEAN" Watch "HELP HELP !!! JSP-BEAN" New topic
Author

HELP HELP !!! JSP-BEAN

Tejas Kansara
Ranch Hand

Joined: Dec 14, 2000
Posts: 38
Hello friends,
Help me out.
This is my Bean file stored in classes folder of JavaWebServer
package mypack;
public class MyBean
{
String usern="";
public void setMessage(String str)
{
usern=str;
}
public String getMessage()
{
return usern;
}
}
This is my .jsp file stored in jsp folder of JavaWebServer.
<jsp: useBean id="obj" class="MyBean" scope="page"/>
<html>
<body bgcolor=orange>
<h1> This is gurus JSP with Bean </h1> <br>
<% String s=request.getParameter("t1");
obj.setMessage(s);
String a= obj.getMessage();
out.println(a);
%>
</body>
</html>
And this is my HTML file
<HTML>
<HEAD>
<TITLE> New Document </TITLE>
</HEAD>
<BODY BGCOLOR="#FFCCFF" text=blue>
<FORM ACTION="http://localhost:8080/examples/jsp/MyBeanPara.jsp">
Enter any Name : <INPUT TYPE="text" NAME="t1" size=25>
<INPUT TYPE="submit">
</FORM>
</BODY>
</HTML>
And this is the error I am getting when I press the SUBMIT button in HTML file.
Error getting compiled page
C:\JAVAWEBSERVER2.0\BIN\..\tmpdir\default\pagecompile\jsp\_examples\_jsp\_MyBeanPara.java:33: Undefined variable or class name: obj
obj.setMessage(s);
^
C:\JAVAWEBSERVER2.0\BIN\..\tmpdir\default\pagecompile\jsp\_examples\_jsp\_MyBeanPara.java:34: Undefined variable or class name: obj
String a= obj.getMessage();
^
2 errors
NOW CAN ANYONE PLEASE EXPLAIN ME WHERE I AM WRONG.
THANKING YOU IN ANTICIPATION.
Regards
Tejas
Maky Chopra
Ranch Hand

Joined: Apr 11, 2001
Posts: 149
try
<jsp: useBean id="obj" class="mypack.MyBean" scope="page"/>
Tejas Kansara
Ranch Hand

Joined: Dec 14, 2000
Posts: 38
I tried by writing mypack.MyBean but still the same problem.
Any other clue.
Reply soon.
Regards
Tejas
Thomas Baumann
Greenhorn

Joined: May 02, 2001
Posts: 10
Hi Tejas,
please tell me the complete path of your MyBean.class-File.
Thomas
Peter den Haan
author
Ranch Hand

Joined: Apr 20, 2000
Posts: 3252
Originally posted by Thomas Baumann:
please tell me the complete path of your MyBean.class-File.

It's got nothing to do with package names or class locations. If it were that, you would've gotten a compiler error that the class could not be found (or maybe a runtime ClassDefNotFoundError). The error tells you that "obj" does not exist, which means that the <jsp:useBean/> is not working. My bet is on the space between "jsp:" and "useBean".
- Peter
Tejas Kansara
Ranch Hand

Joined: Dec 14, 2000
Posts: 38
Hi Peter,
Well as you said I removed the space between <jsp:useBean.../> and then the following result was thrown
Error getting compiled page
C:\JAVAWEBSERVER2.0\BIN\..\tmpdir\default\pagecompile\jsp\_examples\_jsp\_MyBeanPara.java:31: '}' expected.
out.write("");
^
1 error

Pour some light...
Tejas
dharmeshc
Greenhorn

Joined: Apr 16, 2001
Posts: 8
hey there tejas. i just found out that in your code the form tag is without the method attribute ...
also include the following line as the first line in your jsp page
<%@ page language="java" %>
Peter den Haan
author
Ranch Hand

Joined: Apr 20, 2000
Posts: 3252
The out.write("") where the compiler error occurs is generated code. Generally, this means that some of your code right before it isn't correctly terminated (forgotten semicolon, syntax problems). But I can't see anything glaringly wrong in the code you posted.
One of the problems with JSPs is that compiler errors in the generated Java files can be close to meaningless unless you examine those files. So what I'd do is take a look at _MyBeanPara.java, around line 31. Once you do that it is usually pretty clear where the generated code comes from, and what is wrong with it. And you learn a good deal about what happens under JSPs hood besides, which is not a bad thing.
Good luck
- Peter
Raghav Mathur
Ranch Hand

Joined: Jan 12, 2001
Posts: 641
i agree with mak bhandari .... this is your only error boss .


Raghav.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: HELP HELP !!! JSP-BEAN