Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Lots of doubts  RSS feed

 
namrata suri
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I am new to jsp's and beans. Working in Eclipse+tomcat environment.

My aim is to create a drop down menu and one value is selected from it. I need to get this value and print it.

I created a html file "index.html" as follows


<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
<form action="process.jsp" method="post">
<select name="chart_type">
<option value="lc">Line Chart</option>
<option value="bc">Bar Chart</option>
<option value="pc">Pie Chart</option>
<option value="vd">Venn Diagram</option>
</select>
<input type=submit value="Submit">
</form>
</body>
</html>

Now, an action class to process the date from the form and send it is required. That I wrote in GetOption.java

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class GetOption{

String chart_type;
public String getOption()
{
return chart_type;
}
public void setOption(String value)
{
chart_type=value;
}
}


Now, the selected value from here has to be processed by the file i mentioned in action.. which is process.jsp.
Here is the code for that:


<%@taglib uri="/WEB-INF/lib/struts-bean.tld" prefix="bean"%>
<jsp:useBean id="ct" class="GetOption" scope="session"/>
<jsp:setProperty name="ct" property="*"/>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
ChartType: <%= ct.getOption() %>
</body>
</html>

Are there any other files I need to write.

The error I am getting is

org.apache.jasper.JasperException: Unable to compile class for JSP:

An error occurred at line: 2 in the jsp file: /process.jsp
GetOption cannot be resolved to a type
1: <%@taglib uri="/WEB-INF/lib/struts-bean.tld" prefix="bean"%>
2: <jsp:useBean id="ct" class="GetOption" scope="session"/>
3: <jsp:setProperty name="ct" property="*"/>
4: <html>
5: <head>


An error occurred at line: 2 in the jsp file: /process.jsp
GetOption cannot be resolved to a type
1: <%@taglib uri="/WEB-INF/lib/struts-bean.tld" prefix="bean"%>
2: <jsp:useBean id="ct" class="GetOption" scope="session"/>
3: <jsp:setProperty name="ct" property="*"/>
4: <html>
5: <head>


An error occurred at line: 2 in the jsp file: /process.jsp
GetOption cannot be resolved to a type
1: <%@taglib uri="/WEB-INF/lib/struts-bean.tld" prefix="bean"%>
2: <jsp:useBean id="ct" class="GetOption" scope="session"/>
3: <jsp:setProperty name="ct" property="*"/>
4: <html>
5: <head>


Stacktrace:
org.apache.jasper.compiler.DefaultErrorHandler.javacError(DefaultErrorHandler.java:92)
org.apache.jasper.compiler.ErrorDispatcher.javacError(ErrorDispatcher.java:330)
org.apache.jasper.compiler.JDTCompiler.generateClass(JDTCompiler.java:423)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:316)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:294)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:281)
org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:566)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:317)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:337)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:266)
javax.servlet.http.HttpServlet.service(HttpServlet.java:803)


note The full stack trace of the root cause is available in the Apache Tomcat/6.0.16 logs.

 
avi sinha
Ranch Hand
Posts: 453
Google Web Toolkit Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
please use code tags while posting codes otherwise only a few people will pay a heed to it.

avi sinha
 
Sebastian Janisch
Ranch Hand
Posts: 1183
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If your form directly target the JSP you don't need a bean. Simply use ${request.PROPERTY_NAME } ...

Note that this is not the common approach. You always want to have a servlet do all the business logic and leave only presentation to the JSPs.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!