Forums Register Login

HELP HELP !!! JSP-BEAN

+Pie Number of slices to send: Send
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
+Pie Number of slices to send: Send
try
<jsp: useBean id="obj" class="mypack.MyBean" scope="page"/>
+Pie Number of slices to send: Send
I tried by writing mypack.MyBean but still the same problem.
Any other clue.
Reply soon.
Regards
Tejas
+Pie Number of slices to send: Send
Hi Tejas,
please tell me the complete path of your MyBean.class-File.
Thomas
+Pie Number of slices to send: Send
 

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
+Pie Number of slices to send: Send
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
+Pie Number of slices to send: Send
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" %>
+Pie Number of slices to send: Send
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
+Pie Number of slices to send: Send
i agree with mak bhandari .... this is your only error boss .
I'm not sure if I approve of this interruption. But this tiny ad checks out:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com


reply
reply
This thread has been viewed 1176 times.
Similar Threads
jsp beans internal server error 500
jsp
Problem with TreeMap
How to call a bean in a jsp ?
Problem with jsp:useBean tag...URGENT
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 29, 2024 01:32:48.