pinky suresh

Greenhorn
+ Follow
since Jul 21, 2008
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by pinky suresh

If I use HttpURLConnection.setFollowRedirects(true) i am getting 403 error.
Please help me to fix this.
Thanks in advance.
14 years ago
Hi,

Even if I replace HEAD with GET the code does not work.
Please suggest me to feed username and password to server hence bypassing username password prompt while accessing a URL.
14 years ago
Hi,

Can you please brief me on achieving this using java.
Also kindly let me know the mistake that I am doing.
After setting the authenticator with username and password, how to set that authenticator object to url which I am trying to open connection.
I could not find setAuthenticatoe(Authenticator) for urlConnection.

Please help.
14 years ago
Hi,

Yes.. when i enter the url in browser it prompts me for username and password which after entering will take me to the home page.

My requirement is that , the url should not promt me for username and password instead take the details from backend and take me directly to home page.

Please advise how this can be achieved. Also let me know if I am missing any thing.

Kindly let me know if this is feasible using Ajax.If yes, kindly provide me the steps to achieve the same.
14 years ago
Hi,

I have a requirement where I have to check if a applicaiton is running by checking the URL of the applicaiton.
I problem is that applicaition URL is password protected.

My requirement is to access that URL by providing username and password from backend through java program.

I have tried the following..but I am getting 500 as response code instead of 200.

Below is the code that I am trying to run
-----------------------------------------------
public static void main(String[] args) throws IOException {
String userPassword = "nagsures" + ":" + "Qwer$1234";

URL url = new URL("application_url");


HttpURLConnection.setFollowRedirects(false);
String encoding = new sun.misc.BASE64Encoder().encode (userPassword.getBytes());
HttpURLConnection con = (HttpURLConnection) url.openConnection();
con.setRequestMethod("HEAD");
con.setRequestProperty ("Authorization", "Basic " + encoding);
int response = con.getResponseCode();
System.out.println("---response is----" + response);

}

_----------------------------------------------------
I have also tried with Authenticator as well.Below is the code for the same
---------------------------------------------------------
public static void main(String[] args) throws IOException
{
final String login ="nagsures";
final String password ="Qwer$1234";

Authenticator.setDefault(new Authenticator() {
protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication (login, password.toCharArray());
}
});
String url = "application_url";
HttpURLConnection.setFollowRedirects(false);

HttpURLConnection con = (HttpURLConnection) new URL(url).openConnection();
con.setRequestMethod("HEAD");

System.out.println("response code is:: " + con.getResponseCode() );

}
---------------------------------------------------------------------------------
Both the trial programs return 500.
Please help me to fix this. Please let me know how to access a password protected url by providing the username and password from backend.


14 years ago
Hi,

I am learning springs.
In order to run 'Hello World' program in jsp pages using srping, I have done the follwing steps.

In web.xml
---------------
<servlet>
<servlet-name>mySpring</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
</servlet>

<servlet-mapping>
<servlet-name>mySpring</servlet-name>
<url-pattern>*.do</url-pattern>
</servlet-mapping>

Now i have created mySpring-servlet.xml file in web-inf with following content

mySpring-servlet.xml
-------------------------------
<bean id="simpleUrlMapping" class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">
<property name="mappings">
<props>
<prop key="/myWelcome.do">myWelcomeController</prop>
</props>
</property>
</bean>

<bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="viewClass">
<value>org.springframework.web.servlet.view.tiles.TilesView</value>
</property>
</bean>

<bean id="tilesConfigurer" class="org.springframework.web.servlet.view.tiles.TilesConfigurer">
<property name="definitions">
<list>
<value>/WEB-INF/tiles/tiles-config.xml</value>
</list>
</property>
</bean>

<bean id="myWelcomeController" class="welcome.MyWelcomeController">
</bean>

I have defined MyWelcomeController.java file in welcome package. This file just returns a new ModelAndView("myPage") which directs it to a jsp page that prints "Hello World".

Now after deploying my appliaction, when I run my appliaction with url - http://10.65.75.194:8080/Spring/myWelcome.do, I am getting the following error

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'simpleUrlMapping' defined in ServletContext resource [/WEB-INF/mySpring-servlet.xml]: Initialization of bean failed; nested exception is org.springframework.beans.factory.CannotLoadBeanClassException: Cannot find class [welcome.MyWelcomeController] for bean with name 'myWelcomeController' defined in ServletContext resource [/WEB-INF/mySpring-servlet.xml]; nested exception is java.lang.ClassNotFoundException: welcome.MyWelcomeController
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:480)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory$1.run(AbstractAutowireCapableBeanFactory.java:409)
at java.security.AccessController.doPrivileged(Native Method)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:380)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:264)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:261)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:185)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:164)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:429)
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:728)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:380)
at org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:402)
at org.springframework.web.servlet.FrameworkServlet.initWebApplicationContext(FrameworkServlet.java:316)
at org.springframework.web.servlet.FrameworkServlet.initServletBean(FrameworkServlet.java:282)
at org.springframework.web.servlet.HttpServletBean.init(HttpServletBean.java:126)
at javax.servlet.GenericServlet.init(GenericServlet.java:212)
at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1161)
at org.apache.catalina.core.StandardWrapper.allocate(StandardWrapper.java:806)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:129)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:104)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:261)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:844)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:581)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
at java.lang.Thread.run(Thread.java:619)
Caused by: org.springframework.beans.factory.CannotLoadBeanClassException: Cannot find class [welcome.MyWelcomeController] for bean with name 'myWelcomeController' defined in ServletContext resource [/WEB-INF/mySpring-servlet.xml]; nested exception is java.lang.ClassNotFoundException: welcome.MyWelcomeController
at org.springframework.beans.factory.support.AbstractBeanFactory.resolveBeanClass(AbstractBeanFactory.java:1141)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.predictBeanType(AbstractAutowireCapableBeanFactory.java:524)
at org.springframework.beans.factory.support.AbstractBeanFactory.isFactoryBean(AbstractBeanFactory.java:1177)
at org.springframework.beans.factory.support.AbstractBeanFactory.isSingleton(AbstractBeanFactory.java:362)
at org.springframework.context.support.AbstractApplicationContext.isSingleton(AbstractApplicationContext.java:896)
at org.springframework.web.servlet.handler.AbstractUrlHandlerMapping.registerHandler(AbstractUrlHandlerMapping.java:296)
at org.springframework.web.servlet.handler.SimpleUrlHandlerMapping.registerHandlers(SimpleUrlHandlerMapping.java:129)
at org.springframework.web.servlet.handler.SimpleUrlHandlerMapping.initApplicationContext(SimpleUrlHandlerMapping.java:103)
at org.springframework.context.support.ApplicationObjectSupport.initApplicationContext(ApplicationObjectSupport.java:119)
at org.springframework.web.context.support.WebApplicationObjectSupport.initApplicationContext(WebApplicationObjectSupport.java:69)
at org.springframework.context.support.ApplicationObjectSupport.setApplicationContext(ApplicationObjectSupport.java:73)
at org.springframework.context.support.ApplicationContextAwareProcessor.postProcessBeforeInitialization(ApplicationContextAwareProcessor.java:70)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyBeanPostProcessorsBeforeInitialization(AbstractAutowireCapableBeanFactory.java:350)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1331)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:473)
... 28 more

Let me know if I am missing any thing here and possible root cause.
14 years ago
Hi,

Code that we have in CVS is in package structure.

In order to have a local set up, I created web project in MyEclipse and imported the code from CVS.
While imporing, all the java files were imported to src of the project. Now in order to import UI related pages [jsp,html,js] I imported them to webroot folder of my project.

But when i deploy the project, its not able to read the bean definitions from xml file even when the bean definition xml files are in classpath.

I am not able to figure out the mistake that I am doing here.

Please point out the mistake that I am doing & guide me with this.
Hi,

In want to have a local copy of project code and set up a debugging environment in MyEclipse by using code from CVS .

I have downloaded the code from CVS.

Now there are several folders in which each folder has some java files along with web.xml and application-context.xml file,JSP,XML files.
we are using spring with hibernate.

I am not clear on what sections to be copied under web-root , and in src folder of my project.

I copied all java files in packages to src folder by creating the same package name & jsp UI related pages in web root.

But when I deploy this project and run, I am getting "noClassDefinitionError" for spring beans that are clearly defined in bean xml file.

Kinldy let me know if i am missing any thing while creating web project in My Eclipse or please let me know how to create web project from CVS meaning which files should go under which packge.

I hope I have put my question clearly so that its easily understandable.


Hi,

I am learning Hibernate. I wrote a simple application to run SQL queries using hibernate.
I was able to do insert and update. However when I run simple select/delete query I am getting errors which i am not able to solve.

Below is the error i am getting while executing delete query.

I guess the problem is due to the factory class that i am using in hibernate conf file. Please let me know the mistake i am doing and help me learn.

Exception in thread "main" org.hibernate.QueryException: query must begin with SELECT or FROM: delete [delete from newTable table where id=1]
at org.hibernate.hql.classic.ClauseParser.token(ClauseParser.java:83)
at org.hibernate.hql.classic.PreprocessingParser.token(PreprocessingParser.java:108)
at org.hibernate.hql.classic.ParserHelper.parse(ParserHelper.java:28)
at org.hibernate.hql.classic.QueryTranslatorImpl.compile(QueryTranslatorImpl.java:216)
at org.hibernate.hql.classic.QueryTranslatorImpl.compile(QueryTranslatorImpl.java:185)
at org.hibernate.engine.query.HQLQueryPlan.<init>(HQLQueryPlan.java:77)
at org.hibernate.engine.query.HQLQueryPlan.<init>(HQLQueryPlan.java:56)
at org.hibernate.engine.query.QueryPlanCache.getHQLQueryPlan(QueryPlanCache.java:72)
at org.hibernate.impl.AbstractSessionImpl.getHQLQueryPlan(AbstractSessionImpl.java:133)
at org.hibernate.impl.AbstractSessionImpl.createQuery(AbstractSessionImpl.java:112)
at org.hibernate.impl.SessionImpl.createQuery(SessionImpl.java:1623)
at com.hibernate.Test.main(Test.java:45)

Below is the code i am using

public static void main(String[] args)
{
javaClass obj = new javaClass();
obj.setFirstName("Nagasree");
obj.setLastName("Suresh");
obj.setAddress("#1046,14th main,Srinagar");
obj.setEmail("nagasrees@gmail.com");
obj.setId(0);

javaClass obj1 = new javaClass();
obj1.setId(1);
obj1.setFirstName("Rupasree");
obj1.setLastName("Suresh");
obj1.setAddress("Pullman,Saettle");
obj1.setEmail("srupasree@gmail.com");


SessionFactory sessionFactory = new Configuration().configure().buildSessionFactory();
Session session = sessionFactory.openSession();
Transaction transaction = session.beginTransaction();
session.save(obj);
session.save(obj1);

obj.setAddress("#1027,3rd stage,8th main,Gokulam");
session.update(obj);
transaction.commit();

String sqlQuery = "delete from newTable table where id=1";
Query query = session.createQuery(sqlQuery);
int row = query.executeUpdate();
if(row == 0)
{
System.out.println("did not delete any row...");
}
session.close();
}

My java file is

public class javaClass
{
private String firstName = null;
private String lastName = null;
private String address = null;
private String email = null;
private long id = 0;

public long getId() {
return id;
}
public void setId(long id) {
this.id = id;
}
public javaClass() {
super();
System.out.println("--calling no arg constructor---");
}
public String getFirstName() {
return firstName;
}
public void setFirstName(String firstName) {
this.firstName = firstName;
}
public String getLastName() {
return lastName;
}
public void setLastName(String lastName) {
this.lastName = lastName;
}
public String getAddress() {
return address;
}
public void setAddress(String address) {
this.address = address;
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}

}

my hibernate configuration file is
<?xml version='1.0' encoding='UTF-8'?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>

<session-factory>
<property name="connection.username">root</property>
<property name="connection.url">jdbc:mysql://localhost:3309/test</property>
<property name="dialect">org.hibernate.dialect.MySQLDialect</property>
<property name="connection.driver_class">org.gjt.mm.mysql.Driver</property>
<property name="hibernate.hbm2ddl.auto">update</property>
<property name="show_sql">true</property>
<property name="hibernate.format_sql">true</property>
<property name = "hibernate.query.factory_class">org.hibernate.hql.classic.ClassicQueryTranslatorFactory</property>

<mapping resource="myFile.hbm.xml" />
</session-factory>
</hibernate-configuration>

my mapping file is

<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">

<hibernate-mapping>
<class name="com.hibernate.javaClass" table="newTable" >
<id name="id" type="long" column="id" length="2">
<generator class="assigned"></generator>
</id>

<property name="firstName"></property>
<property name="lastName"></property>
<property name="address"></property>
<property name="email"></property>

</class>
</hibernate-mapping>
Hi,

I tried removing servlet-api,jsp-api.jar files.

On removing them,i am getting NoClassDefFoundError for HttpServletRequest and JSPFactory.

15 years ago
JSP
I have the following jar files in WEB-INF/lib

ant,commons-logging,common-el,jsp-api,log4j,servlet-api,jasper-compiler.jar files and a few other jasper jar files.

15 years ago
JSP
Hey,
Thanks a lot for replying...

I removed those jars,but still getting the same error.Now what could be the reason for getting the same error?

jar files will be added in Tomcat's lib right...so there is no need to explicitly add these jars in WEB-INF/lib.Am I right?

15 years ago
JSP
I have jsp-api.jar and servlet-api.jar file copied into WEB_INF/lib..
Are you referring to these jars only?
Should these jar files be removed?
15 years ago
JSP
Hi,
I am trying to use c:forEach tag in a JSP to simply iterate through a list and display the items in jsp page but I am getting the following error

java.lang.IllegalAccessError
org.apache.taglibs.standard.tlv.JstlCoreTLV.getHandler(Unknown Source)
org.apache.taglibs.standard.tlv.JstlBaseTLV.validate(Unknown Source)
org.apache.taglibs.standard.tlv.JstlCoreTLV.validate(Unknown Source)
org.apache.jasper.compiler.TagLibraryInfoImpl.validate(TagLibraryInfoImpl.java:759)
org.apache.jasper.compiler.Validator.validateXmlView(Validator.java:1522)
org.apache.jasper.compiler.Validator.validate(Validator.java:1490)
org.apache.jasper.compiler.Compiler.generateJava(Compiler.java:167)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:296)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:277)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:265)
org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:564)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:302)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:329)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:265)
javax.servlet.http.HttpServlet.service(HttpServlet.java:803)


Jstl.jar and standard.jar files are included in lib. Is the compiler not able to find these jar files??Can you please let me know why am I getting this problem.
Please reply...
15 years ago
JSP
Hi,

I have a doubt in method overriding. If a superclass has a method that throws an Excpetion and the same method is overridden in subclass & the overridden method does not throw any exception, still that method should be called within try catch block in the implementing class. Why is it so??
See below example for clear idea on my doubt.

public class Shape
{
public void displayShape() throws Exception
{
System.out.println("displayShape in superclass ");
}
}

public class Circle extends Shape
{
public void displayShape()
{
System.out.println("displayShape in circle");
}

public static void main(String[] args)
{
Shape c = new Circle();
c.displayShape();
}
}

Compiler says to sorround Circle's displayShape() in a try-catch block. Please let me know why this method should be sorrounded with try-catch block even when the overridden method in Circle class does not throw any Exception.
15 years ago