N Nanda

Ranch Hand
+ Follow
since Feb 09, 2004
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 N Nanda

Hi..

Brent's approach is absolutely fine. Use a Business Deligate class which is nothing but a plane java class (POJO approach) which takes care of all EJB specific tasks. However, don't put your JNDI lookups into deligate class. Rather use Service Locator pattern to do that. A Service Locator is again a java class which may contain methods (say) like , which may do all the JNDI lookups for an EJB (say) CustomerManagerEJB and keeps that remote reference in a Hashtable so that next time you require the same reference, you can get it from the Hashtable. Just search in SUN's web site for Service Locator pattern. And with the help of Business Deligate and Service Locator patterns you can isolate your business layer from web layer. And your struts action class or other servlets may call methods on Business Deligate class only.

Hope this helps.

Regards,
Niranjan
13 years ago
Hi To All...

I am working in a project where we need to call some VC++ methods from our JSP files. Can anyone tell how exactly I must proceed to accomplish it. Means where I must put the dll files and java class files so that JNI works. And if there is any other way to call VC++ methods from JSP, please inform me as soon as possible.

Thanks in advance.

regards,
Niranjan.

[Bear edit: not so urgent]
[ April 04, 2005: Message edited by: Bear Bibeault ]
14 years ago
JSP
Hello to all... I am working on a project which requires remote controlling of the gadgets connected to a machine. The requirement some external gadgets/devices are connected to a machine through some port and the machine is hosting some web server. I have to control the devices remotely over the web. In order to achive this, the server side script must be able to handle the queries/commands from the user and interact with the connected devices. Is it possible in java ? Kindly reply as soon as possible. I need it very urgently.

Thanks all in advance.
14 years ago
Hello Manish.. Try this simple example and I hope it'll help you.

Suppose you have a business logic component BooksDAO which has few methods like getAllBooks(...) and addBook(...) etc. Now in a view (say)books.jsp you hav links like View All Books, Add A Book, etc..
You can build those links like...
<html:link href="/manageBooks.do?page=view">View All Books</html:link>

Now write the following Action class ManageBooks.java


package pack1;
// imports
public class ManageBooks extends DispatchAction implements java.io.Serializable
{
public ActionForward view(ActionMapping mapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) throws Exception
{
//Call the business logic getAllBooks() here
return mapping.findForward("view");
}

// Similarly we can put another method say add
public ActionForward add(ActionMapping mapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) throws Exception
{
//Call the business logic addBook() here
return mapping.findForward("add");
}
}// End of class

--------------
Now in your struts-config.xml file write the following to invoke the dispatch actions

<action path="/manageBooks" type="pack1.ManageBooks"
scope="request" validate="false" parameter="page" input="books.jsp">
<forward name="view" path="/viewBooks.jsp" redirect="true"/>
<forward name="add" path="/addBooks.jsp" redirect="true"/>
</action>

Now in above action, the parameter attribute is important as according to it, the methods in the disptch action classes will be deligated.

regards,

Niranjan
14 years ago
Hello to all. I am using Struts for my project. I have a form with two drop-down-lists. I want to fill the second list according to selection in first one. Can anyone help me achive this please. Its an urgency.

Thanx in advance,

Niranjan Nanda
14 years ago
Hello..

i am using MySQL database which is residing on another server and my development (struts stuffs) are on a separate machine. I have configured datasource in struts-config.xml file. I am trying to retrieve data from a table with following codes...

In my UserDAO class I have a method getAllUsers() which returns an ArrayList containing all users (I have a User bean). In my UserAction class I have called that method getAllUsers() and set its returning ArralyList in request scope. In my jsp page I am using display-tag to display the collected data. But it doesn't show any data.. The display-tag shows its default error message "Nothing Found To Display". Can anyone tell what could be the problem. Please.

Thank you all in advance

N. Nanda
14 years ago
Thanks Marc and Srinath. I checked my web server log and the trace was showing that it was failing to get the definition of BookForm. Then I checked my struts-config.xml and there I had a wrong classpath. However, even after I changed the classpath it wasn't working. Then I created that BookForm class again and after that it worked as I require. But thank you both for giving me the idea of tracing the webserver log. Sorry if I have disturbed you for this small problem. I'll get back to you if I'll face any problems.

Thank you again.

Niranjan Nanda.
14 years ago
thanx srinath.. but i have this filed in my BookForm with getters and setters properly set for it. Can you point out any other problem ?? Mr. Marc. answered that I should get 404-error, but I didn't understand his point clearly. Kindly tell me if you can find any other problems. I'll give you the stack trace that could have appeared in the log file.

Thank you again.

Niranjan Nanda
14 years ago
Try to go through the supplied struts-example webapp with struts package. It has a good example on that.

Regards,
----------

Niranjan Nanda
14 years ago
Thanx Marc for your response. In my address bar I am getting
http://localhost:8080/manageBook?action=addNew

But a blank screen in place of content area. I am not sure about your skepticism regarding 404-error, but I am getting a complete blank screen. And if I am disabling the <html:form ..> part in my /books/addBooks.jsp page then I am getting that page easily, I mean no blank screen, the page is coming ok. I have few other things in that page except that Book adding form like I have displayed a heading "Add A Book" and this header is coming properly if I am commenting out that <html:form ... > part. But If that form part is uncommented, I am getting a blank screen.

Please help me. Its really urgent and please if possible add some comments where I could be going wrong.

Thank you again.

Niranjan Nanda.
14 years ago
Hello Archana,

I don't know whether my concept is right or wrong, but through a common html link <a href .....> you cannot activate an action. To activate a struts action through a link, struts provides its own link tag and I hope you must know about it. Its <html:link>. try to read a little bit detail about it in struts-documentation. I am providing a small example about activating an action through <html:link> tag.

Suppose your struts-config.xml file has entries like below.


<global-forwards>
<forward name="home" path="/index.do" />
</global-forwards>

<action-mappings>
<action path="/index"
type="mylib.IndexAction">
<forward name="success" path="/homepage.jsp" />
</action>
</action-mappings>


Now suppose in your page1.jsp has an entry like...


<html:link forward="home">Click Here For Homepage</html:link>


Now what it tells, when in your page1.jsp page you will click on that link, it'll search your struts-config.xml file for a forward with name home. And in your struts-config file you have actually activated once action index.do for this forward name. Right ?? Now ultimately you'll be forwarded to homepage.jsp page. If you'll view the source of that page1.jsp then, you'll find that above link statement is converted to <a href="/homepage.jsp">Click Here For Homepage</a>.
14 years ago
Well.. try to use display-tag. Its good and it provides a lot of features like generating automatic links, sorting a column etc. The link for this is http://displaytag.sourceforge.net . This site provides a good documentation with some good examples. Hope it'll help you.

Regards,

Niranjan Nanda
14 years ago
Thank you all for their responses. Here I am putting part of my coding. Kindly somebody check it and help me to solve my problem.


struts-config.xml
===========

<form-beans>
<form name="bookForm" type="lib.book.BookForm" />
</form-beans>

<global-forwards>
<forward name="home" path="/index.jsp"/>
<forward name="bookHome" path="/books/index.jsp"/>
</global-forwards>

<action-mappings>
<actionpath="/manageBook"
type="lib.book.ManageBook"
name="bookForm"
validate="false"
scope="request"
parameter="action"
input="/books/index.jsp">
<forwardname="success"path="/books/index.jsp"/>
</action>

<actionpath="/saveBook"
type="lib.book.SaveBook"
name="bookForm"
validate="false"
scope="request"
input="/books/index.jsp">
<forwardname="success"path="/books/index.jsp"/>
</action>
</action-mappings>

$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$

ManageBook.java
================

package lib.book;

import javax.servlet.http.*;
import org.apache.struts.action.*;
import org.apache.struts.actions.DispatchAction;
import java.util.ArrayList;

public class ManageBook extends DispatchAction
{
public ActionForward view( /* The usual arguments */...) throws Exception
{
String action = request.getParameter("action");

if(action == null) {
action="view";
}

if("view".equalsIgnoreCase(action)) {
/*
*Here I have retrieved all existing books from database and stored in an arraylist
*ArrayList allBooks=new ArrayList();
*/

request.setAttribute("action", action);
request.setAttribute("books", allBooks);
}

/* Here I have removed any FormBean if it is created. */

return mapping.findForward("success");
}

public ActionForward addNew( /* The usual arguments */...) throws Exception
{
String action = request.getParameter("action");

if(action == null) {
action="addNew";
}


if("addNew".equalsIgnoreCase(action)) {
request.setAttribute("action", action);
}

return mapping.findForward("success");
}
}

$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$

SaveBook.java
================

package lib.book;

import javax.servlet.http.*;
import org.apache.struts.action.*;

public class SaveBook extends Action
{
public ActionForward execute( /* The usual arguments */...) throws Exception
{
Book book= new Book();
BookForm bookForm = (BookForm)form;

String action=bookForm.getAction(); /* This I send from the form as a hidden field. */
String target="error";

book.setBookId(bookForm.getBookId());
...
...
...

if("addNew".equalsIgnoreCase(action)) {
target=doSave(request, book);
}
else if("edit".equalsIgnoreCase(action)) {
target=doUpdate(request, book);
}

return mapping.findForward(target);
}

private String doSave(HttpServletRequest request, Book book) throws Exception
{
String target = BookDAO.addBook(getDataSource(request), book);
return target;
}

private String doUpdate(HttpServletRequest request, Book book) throws Exception
{
String target = BookDAO.updateBook(getDataSource(request), book);
return target;
}
}

$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$

/books/index.jsp
===============
...
...
...

<logic:equal name="action" value="view" scope="request">
<template ut name="content" content="/books/viewBooks.jsp" />
</logic:equal>

<logic:equal name="action" value="addNew" scope="request">
<template ut name="content" content="/books/addBooks.jsp" />
</logic:equal>
...
...

$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$

/books/addBooks.jsp
===============
...
...
...

<html:form action="saveBook" focus="bookId">
<html:hidden property="action ... ... />
...
...
...
</html:form>

==========================

Thanx in advance.

Niranjan Nanda
14 years ago
Thanks for the replies. I get a blank screen. Kindly tell me in detail what could be the problem. Thank you in advance.
14 years ago
Hi all... I am using struts to design an online Library system for my organization. I have an action class called ManageBooks.java which extends DispatchAction. It has 2 mthods view() and addNew() which are actually configured with parameter name "action" in my struts-config.xml file. There are 2 links in the books home page "View" and "Add". My idea is when I'll click Add link, it should display a blank form (name is BookForm) and let me add a new book. But its not working. Can anyone tell what could be the problem ??...

My struts-config file contains these entries...

<action-mapping>
<action path="manageBooks"
type="lib.books.ManageBooks"
name="bookForm"
validate="false"
scope="request"
parameter="action"
input="/index.jsp">
<forward name="success" path="/books/index.jsp" />
</action>
<action path="saveBooks"
type="lib.books.SaveBooks"
name="bookForm"
validate="false"
scope="request"
input="/index.jsp">
<forward name="success" path="/books/index.jsp" />
</action>
</action-mapping>

My problem is the BookForm is not displayed. I have checked that the addNew() method is called properly, but the Form is not displayed. Kindly help me.

Thanks in advance.

N. Nanda
14 years ago