File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Struts and the fly likes Not able to run JSP Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Not able to run JSP " Watch "Not able to run JSP " New topic
Author

Not able to run JSP

Vijendra Babar
Greenhorn

Joined: Jul 28, 2006
Posts: 18
Hello friends,

I have written small application which is currently deployed on Linux machine with Tomcat 5.5 version & JDK1.5.0_06.

First I wrote normal application which contains main()
Following is the code which I have used.

Class.forName("com.mysql.jdbc.Driver");
con = DriverManager.getConnection("jdbc:mysql://iccs1:3306/test?user=root&password=");

This code is working absolutly fine when application is runned.

Now I want ot convert this application into web based.
For that I am using Struts 1.2 & JSP 1.2

Following is the code in my action

import java.io.FileOutputStream;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.sql.Statement;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.sql.DataSource;

import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

import com.solversa.beans.excelFormBean;

/**
* @author jkl
*
* TODO To change the template for this generated type comment go to
* Window - Preferences - Java - Code Style - Code Templates
*/
public class excelAction extends Action{

public ActionForward execute(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws Exception
{
excelFormBean beanForm = (excelFormBean)form;

Connection con;
Statement stmt;
ResultSet rs;
ResultSetMetaData rsMeta;
DataSource dataSource;


System.out.println(" File Name = " + fileName);
try
{
System.out.println(" 1 " );
/* Connection to be made to MySql for getting data & inserting it to Excel sheet */
Class.forName("com.mysql.jdbc.Driver");
System.out.println(" 2 " );
con = DriverManager.getConnection("jdbc:mysql://iccs1:3306/test?user=root&password=");
System.out.println(" 3 " );
stmt = con.createStatement();
System.out.println(" 4 " );
rs = stmt.executeQuery("Select * from Excel");
System.out.println(" 5 " );

rs.close()
con.close();
request.setAttribute("result"," created successfully.");
}
catch(Exception ee)
{
request.setAttribute("result"," not created successfully.");
System.out.println("\n\nError Found : " + ee.toString());
}
return mapping.findForward("success");
}
}


Now when ever this action is called, it rpompts me error as:
java.sql.SQLException: Unable to connect to any hosts due to exception: java.net.UnknownHostException: iccs1

While same code in normal application i.e. public static void main(String args[]) works perfectly without any error.

Can u pls help me out.
Is this problem of JSP or Struts or Tomcat?
Merrill Higginson
Ranch Hand

Joined: Feb 15, 2005
Posts: 4864
The error message is telling you it can't find the host.

I notice that your database host name does not have any domain name attached to it. By that, I mean you have "iccs1" rather than "iccs1.mycompany.com". If iccs1 is a remote system, chances are you will need a domain name in order to connect to it. Log on to your Linux system Try to ping "iccs1". If the ping fails, then you have verified that the host name is the problem. You will need to find the right host name that will connect to your MYSQL database.

Note: It is not considered a good practice to use this method of connecting to a database in a web application. The best practice is to use connection pooling. This link explains how to set it up.


Merrill
Consultant, Sima Solutions
Vijendra Babar
Greenhorn

Joined: Jul 28, 2006
Posts: 18
Hi Merrill,
I got another solution & works fine.
The thing is that I changed my Host name i.e. ICCS with IP address.

This is working fine.

Thanks for your help.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Not able to run JSP