• 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

what am i doing wrong URGENT (this is my true posting)

 
Ranch Hand
Posts: 331
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This is my first attempt at both an Applet and Servlet. I hope you can take the time to help me, I really need the help. Im trying to obtain for the moment simply the user name and in turn this information will be saved to SQL. Im using the Applet --> Servlet --> JDBC --> SQL strategy. The problem that im having is that in the line marked ** im not connecting to my Servelt- I think. Because no errors are thrown but the information is never transfered to SQL. I have placed several System.println statements and the last one is executed in my applet class. I hope I was clear and If you need more info please ask. Thank you all for your time.
public class First extends Applet
{
public void addName()
{
try
{
URL dataURL = new URL("http://caaove01/bryantest/JAVA/t/Serv");
URLConnection connection = dataURL.openConnection();
connection.setDoInput(true);
connection.setDoOutput(true);
connection.setUseCaches (false);
connection.setDefaultUseCaches(false);
// Specify the content type that we will send binary data
connection.setRequestProperty ("Content-Type", "application/octet-stream");
**ObjectOutputStream out = new ObjectOutputStream(connection.getOutputStream());
out.writeObject(getTextField1().getText());
out.flush();
out.close();
}
private Button getButton1()
{
ivjButton1.addActionListener(new ReflectiveAction(this, "addName"));
return ivjButton1;
}
//Servlet code
public class Serve extends HttpServlet
{
private InfoGetter info;
public void doGet(javax.servlet.http.HttpServletRequest .....
performTask(request, response);
public void doPost(javax.servlet.http.HttpServletRequest ....
{
performTask(request, response);
}
public void init()
{
info = new InfoGetter();
}
public void performTask(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response) {
try
{
ObjectInputStream objIn = new ObjectInputStream(request.getInputStream());
String person = (String)objIn.readObject();
objIn.close();
info.addPersInfo(person);
}

}
//Connection to SQL
public class InfoGetter
{
public InfoGetter()
{
String dsn = "jdbc:twtds:sqlserver...";
try
{
Class.forName("com.thinweb.tds.Driver");
myCon = DriverManager.getConnection(dsn, "this", "that");

}
public void addPersInfo(String first)
{
try
{
PreparedStatement statement = myCon.prepareStatement(
"INSERT INTO email ([Name]) VALUES (?)");
statement.setString(1,first);
statement.executeUpdate();
statement.close();
 
Author and all-around good cowpoke
Posts: 13078
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I see lots of try{ block starts but I don't see any catch statements where you print out or log the exceptions. Is that really the way your code reads?
Bill
 
Saloon Keeper
Posts: 27796
196
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
A superficial glance seems to tell me that you're attempting to serialize objects. That can cause all sorts of grief since the receiver may not be compatible with the sender.
Over the years I've come to the conclusion that one should never use a binary format when a text one will do. Binary can't be read without a suitable decoder program, the available tools for manipulation are fewer, when you do inter-system work you get clobbered by byte-order and other hardware issues. I think it was Microsoft that finally convinced me once and for all - if just ONE of their OLE files gets scrambled, an entire system can sometimes topple.
Most of the old arguments for using binary are pretty pointless - we have sufficient hardware capacity to store and transmit it, and bandwidth and security issues can often be resolved at the hardware level using standardized compression and encryption firmware (or at least at some other layer than the application).
Not that I think Java is going to drop serialization - it does have its uses. However, you're not the first to discover the hard way that serialization between and applet and a server isn't a guaranteed success.
 
William Brogden
Author and all-around good cowpoke
Posts: 13078
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I think serializing a String is pretty safe. Serialization is essential to many key Java capabilities, but as you say, the problem comes if both sides have different object versions.
XML & SOAP are much more flexible in that situation.
Bill
reply
    Bookmark Topic Watch Topic
  • New Topic