Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

HELP HELP !!! JSP-BEAN

 
Tejas Kansara
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 149
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
try
<jsp: useBean id="obj" class="mypack.MyBean" scope="page"/>
 
Tejas Kansara
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I tried by writing mypack.MyBean but still the same problem.
Any other clue.
Reply soon.
Regards
Tejas
 
Thomas Baumann
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Tejas,
please tell me the complete path of your MyBean.class-File.
Thomas
 
Peter den Haan
author
Ranch Hand
Posts: 3252
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 38
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 3252
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 641
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i agree with mak bhandari .... this is your only error boss .
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic