• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

how can we call valueobject class in servlet

 
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In my servlet i called a valueobject file using import statement.....
import ValueObject.*;
But it is showing package not found...
help urgently needed
 
Sheriff
Posts: 13411
Firefox Browser VI Editor Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Where did you put the class file?
Also, your classes will need to be in a package.
 
Sheriff
Posts: 67749
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Please read this.
 
jothish chokkalingam
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
i put the class file in C:\Program Files\Apache Group\Tomcat 4.1\webapps\ROOT\WEB-INF\classes
my valueobject code...
package ValueObject;
public class ValueObject
{
String dept;
private String getDept()
{
return dept;
}
private void setDept(String str)
{
dept=str;
}
}
 
Sheriff
Posts: 14691
16
Eclipse IDE VI Editor Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Do you know what a package is ?
Your package name, with CapitalLetters, is strange and matches your class name.

Where did you put ValueObject.java ?
 
Ranch Hand
Posts: 1704
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by jothish chokkalingam:
i put the class file in C:\Program Files\Apache Group\Tomcat 4.1\webapps\ROOT\WEB-INF\classes
my valueobject code...
package ValueObject;
public class ValueObject
{
String dept;
private String getDept()
{
return dept;
}
private void setDept(String str)
{
dept=str;
}
}


You class should be under
C:\Program Files\Apache Group\Tomcat 4.1\webapps\ROOT\WEB-INF\classes\ValueObject and not

C:\Program Files\Apache Group\Tomcat 4.1\webapps\ROOT\WEB-INF\classes\

But its not good to use same class name same package name. And as per coding stndards package name should start with small letter.
 
jothish chokkalingam
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
nope reddy its not working.....
my valueobject class is in the path...
C:\Program Files\Apache Group\Tomcat 4.1\webapps\ROOT\WEB-INF\classes\value
package value;
public class ValueObject
{
public String dept;
public String getDept()
{
return dept;
}
public void setDept(String str)
{
dept=str;
}
}
the action class is in
C:\Program Files\Apache Group\Tomcat 4.1\webapps\ROOT\WEB-INF\classes
import java.io.*;
import java.lang.*;
import java.net.*;
import java.sql.*;
import java.util.*;
import java.sql.*;
import java.io.File;
import java.util.Date;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.*;
import javax.servlet.ServletOutputStream;
import javax.servlet.*;
import value.ValueObject.*;
public class SimpleServlet1 extends HttpServlet
{

public void doGet(HttpServletRequest request,
HttpServletResponse response)
throws ServletException, IOException
{
try{
PrintWriter out1 = response.getWriter();
DriverManager.registerDriver (new oracle.jdbc.driver.OracleDriver());
Class.forName ("oracle.jdbc.driver.OracleDriver");
Connection conn=DriverManager.getConnection("jdbc racle:thin:@10.236.8.49:1521:heb","hebuser","hebpass");
// @machineName ort:SID, userid, password
//int i=0,j=0;
String query = "select * from storeevent1";
Statement stmt = conn.createStatement();
ResultSet rs = stmt.executeQuery(query);
out1.println("from servlet");
value.ValueObject v1=new value.ValueObject();




v1.setDept("chenai");
System.out.println(v1.dept);
ServletContext ctx = getServletContext();
System.out.println(ctx);
RequestDispatcher dispatcher = ctx.getRequestDispatcher("/jsp.jsp");

request.setAttribute("data",v1);

dispatcher.forward(request,response);


}
catch(Exception e)
{
e.printStackTrace();
}
}
}
my target jsp page is in C:\Program Files\Apache Group\Tomcat 4.1\webapps\ROOT
<HTML>
<BODY>
<%@ page import="value.ValueObject.*" %>
<%@ page import="java.lang.*" %>
Hello! The time is now <%= new java.util.Date() %>
<% String s=request.getParameter("fyear");
java.lang.Object v2;
v2=request.getAttribute("data");
String dept1=v2.getDept();

%>
<p>
<%=s %>

</p>
<p>
dept
</p>
</BODY>
</HTML>
please help me out .........
 
Greenhorn
Posts: 18
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hey dude..

what are you doing

your package is value

and your class is ValuePackage

so you can write either

import value.*;


or

import value.ValuePackage;

I hope it will help you out
 
Abhinit Saxena
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sorry...replace ValuePackage to ValueObject;
 
Ranch Hand
Posts: 1026
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
import value.ValueObject; (or)
import value.*;
 
Kj Reddy
Ranch Hand
Posts: 1704
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Your import statement is wrong.
import value.ValueObject.*;

Use:
import value.ValueObject;

or

import value.*;
 
Abhinit Saxena
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I noticed one more thing in your code...

you used out.println()
and then forwarding to another page???


Dont you think so it will throw you IllegalStateException???
 
jothish chokkalingam
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
i didn't type cast the object to my valueobject class....
like
ValueObject v2 = new ValueObject();
v2=(ValueObject)request.getAttribute("data");
 
Abhinit Saxena
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Remember:
========
your ValueObject class is now in value package..

you have to use it like

value.ValueObject or

<%@ page import="value.ValueObject"%>
.....

.....
ValueObject v2 = new ValueObject();


as your JSP will convert in to servlet and gone to another package (org.apache.....)
 
jothish chokkalingam
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
ya dudes.....
i got it right
reply
    Bookmark Topic Watch Topic
  • New Topic