Chan Yan

Greenhorn
+ Follow
since Oct 21, 2005
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 Chan Yan

Vertion 1 of Tiles used to be support to fire action (.do in struts 1) in tiles-defs.xml. For some reason, it doesn't works same way in tiles 2.
14 years ago
I am testing to fire a struts2 action from tiles definition (tiles-defs.xml). The action was fired, but it goes to infinite loop and can't stop. I notice it by adding a breakpoint in execute() method of ToHeaderAction.java, in debug mode. I think there is something wrong in web.xml but I don't know what is. Does anyboby help me to figure it out? thanks in advance.

I use Struts 2.1, tiles 2, tomcat 6, following jar files in the lib folder
struts-core-1.3.10.jar
struts2-core.2.1.6.jar
struts-tiles-plugin-2.0.11.1.jar
tiles-api-2.0.6.jar
tiles-core-2.0.6.jar
tiles-jsp-2.0.6.jar


below is the code.

web.xml

-----------
Struts xml

-------------

tiles-defs.xml

---------
index.jsp

------------

standard-layout.jsp

-------
siteHeaderTile.jsp

--------------
ToHeaderAction.java

---------------
MainPageAction.java

14 years ago
Hello, Ramesh David,

Did you figure out how to fire action in tiels.xml (in struts2/tiles2)? I have same problems now.

Thanks.
14 years ago
Thanks, yash wardhan. I fix it. Since I defined namespace="/" in struts.xml for action 'starttoshow' in <package tag, I need to indicate it in index.jsp also. (If no 'namespace' defined in struts.xml for the action, it doesn't need to use it in index.jsp) So, index.jsp should look like:


And 'executeResult="true"' is for display the result, otherwise an blank page will show up.
15 years ago
Thanks, yash wardhan. I did try to add .action in the jsp file. The index.jsp looks like this:

It didn't work and error message is following:



If I don't use index.jsp to redirect the page, .action itself works fine (using 'http://...../starttoshow.action'). I think the error maybe from redirect. If it is the case, what's the right way to redirect in a jsp file?
15 years ago
Hello, everybody. I try a simple Struts 2 app to start learning it. The error message 'The requested resource (/s2_asciimonitor/starttoshow.action) is not available' keeps showing up if url is 'http://localhost:8080/s2_asciimonitor/index.jsp' (in 2 ways, 1. jsp forward and s:action. none of them works). But if I put url as 'http://localhost:8080/s2_asciimonitor/starttoshow.action'. It works. I can't figure out where causes the error. Please help me. Thanks in advance. northcloud

Here is my code:
struts.xml (in '\WEB-INF\classes' after deploy)

-----------
web.xml

-------------------------------------
StartToShowAction.java

----------------------------------
showIt3.jsp

---------------
index.jsp
15 years ago
I am working on a project using Struts 1.2 (not Struts 2). The project is used to create RSS feed and process RSS subscription. I found Rome is good to generate the feeds. But its output is with Roms's class SyndFeedOutput. How can I integrate it with Struts ActionMapping.findForward("success") and forward to a jsp page with my own header and footer in the jsp page? Thanks.
16 years ago

Originally posted by Bear Bibeault:
All of that is not necessary.

Use <c:import> to load the XML file into a scoped variable, and then use <c:out> to display it. The <c:out> will automatically convert the markup to HTML entities.



Thank you, Matt W Robinson & Bear Bibeault. I tried to use <c:import . It works. The page shows the content of the XML in plain text as a long string. I want to know if any good way to make it looks better, like each item shows on seperated line. Anyway, thank both of you very much.
16 years ago
JSP
I use <jsp:include page=".....xml" /> tag in a jsp file to include an xml file. When this jsp page is open, only the text content in the xml file shows up with plain text. I want this xml file shows up like in IE (with xml format). Does anyone know how to do it? Thanks.
16 years ago
JSP
Hi everyone, I am working on a small website using JSP/Struts on my local computer. The index page is index.jsp with a jsp tag to forward to call a servlet. Now I need to upload the whole site to a shared Tomcat host. It requires that the start page of my site must have index.html name. Does anyone know how I can implement this? How to automatically call a servelt in a HTML file? Thanks in advance. CY

Here is my index.jsp file (just one line)

<jsp:forward page="/homepage.do"/>
16 years ago
JSP
Hello everyone,
I use a Shared Tomcat Java hosting to host my site and have below error message:


But there is no problem to run on my local computer (I use Tomcat 5.5.25), and my site runs well on the local computer.

The host provider sent me a piece of messages in server log file, it said:


I have checked the web.xml, it is there under '/WEB-INF/'. How can it be missing? And they said, 'You should also install log4j to have your own Tomcat log to debug your application.'. I do have log4j log file inside the application. But I think that the error is on tomcat server starting. How can I log these kind of messages into my application log file?
I uploaded a small java class and jsp file to the server to test the db connection (see the below). I get same error message on the screen:


Does anyone know how I can fix the problem and what I can do next? Thanks in advance.

Related files are below.

A part of web.xml

Java test class:

test.jsp
16 years ago
Hello everyone,
I use a Shared Tomcat Java hosting to host my site and have below error message:


But there is no problem to run on my local computer (I use Tomcat 5.5.25), and my site runs well on the local computer.

The host provider sent me a piece of messages in server log file, it said:


I have checked the web.xml, it is there under '/WEB-INF/'. How can it be missing? And they said, 'You should also install log4j to have your own Tomcat log to debug your application.'. I do have log4j log file inside the application. But I think that the error is on tomcat server starting. How can I log these kind of messages into my application log file?
I uploaded a small java class and jsp file to the server to test the db connection (see the below). I get same error message on the screen:


Does anyone know how I can fix the problem and what I can do next? Thanks in advance.

Related files are below.

A part of web.xml

Java test class:

test.jsp
Hello everyone,
I use a Shared Tomcat Java hosting to host my site and have below error message:


But I don't have any problem to run on my local computer (I use Tomcat 5.5.25), and my site runs well on the local computer.

When I read doc on 'http://tomcat.apache.org/tomcat-5.5-doc/jndi-resources-howto.html'. I found this paragraph in the page:

In addition, the names and values of all <env-entry> elements included in the web application deployment descriptor (/WEB-INF/web.xml) are configured into the initial context as well, overriding corresponding values from conf/server.xml only if allowed by the corresponding <Environment> element (by setting the override attribute to "true").


Does anyone know how to this 'override' attribute to "true"? where is it suppose to be? Is it the issue to cause the error?

Thanks in advance.

----------
Here is my context.xml (under '/public_html/META-INF/') and part of web.xml (under '/public_html/WEB-INF/'). I have a test.jsp to test the connection. I found the error occurs at this line in class DBTest.java

conn = ds.getConnection();
-----------------

[ October 15, 2007: Message edited by: Bear Bibeault ]
Thank you, Carol Enderlin. This is my mistake (I didn't notice it, so silly). Once I take off 'private static DataSource dataSource;' from class AdminLoginBO, it works. Thank you again. I am sorry I didn't use 'code' tag. I won't forget it for sure.

Originally posted by Carol Enderlin:
Please use code tags in the future!



Is the private static dataSource variable hiding the one in the superclass (BaseLinkBO)?

16 years ago
JSP
Hello. I am working on a small projest using Struts and defining JNDI to get datasource. In the login page, when 'submit' is clicked, I get error messages:

WARN : 2007-10-01 13:52:34,658 [http-8080-Processor25] RequestProcessor - Unhandled Exception thrown: class java.lang.NullPointerException
ERROR: 2007-10-01 13:52:34,758 [http-8080-Processor25] [action] - Servlet.service() for servlet action threw exception
java.lang.NullPointerException
at com.swlAdminJ.bo.AdminLoginBO.findByName(AdminLoginBO.java:31)
at com.swlAdminJ.action.login.LoginSubmitAction.execute(LoginSubmitAction.java:32)
at org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:431)
at org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:236)
at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1196)
at org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:432)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:709)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:252)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:213)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:178)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:126)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:105)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:107)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:148)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:869)
.......



I found that the 'dataSource' in 'findByName(String aName, String aPwd)' of class 'AdminLoginBO' was null. I can't figure out why this dataSource is null. Does anyone have idea what causes the error? Thanks in advance.

Here are part of the code. I use Tomcat 5.5, struts 1.1, mysql 5.0 and Eclipse. 'mysql-connector-java-5.0.7-bin.jar' is under '..\Tomcat5.5\common\lib'.

context.xml under 'WebRoot\META-INF' is:
<?xml version="1.0" encoding="UTF-8"?>
<Context >
<Resource
auth="Container"
description="DB Connection"
name="jdbc/myDataSource"
type="javax.sql.DataSource"
driverClassName="com.mysql.jdbc.Driver"
maxIdle="2"
maxWait="5000"
username="root"
password="root"
url="jdbc:mysql://localhost:3306/my_db?relaxAutoCommit=true"
validationQuery="select 1"
maxActive="4"/>
<WatchedResource>WEB-INF/web.xml</WatchedResource>
<WatchedResource>META-INF/context.xml</WatchedResource>
</Context>

---------------------
web.xml (part of it)
<web-app xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="2.4" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
<resource-ref>
<description>DB Connection</description>
<res-ref-name>jdbc/myDataSource</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
</resource-ref>

<servlet>
.....
</servlet>
</web-app>
-----------------
Login action class (when 'submit'button is clicked, this one is executed):


public class LoginSubmitAction extends Action
{
public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response)
throws Exception
{

ActionForward returnForward = null;
AdminLoginBO curAdminBO = AdminLoginBO.getInstance();

String userId = (String)((DynaValidatorForm)form).get("userId");
String pwd = (String)((DynaValidatorForm)form).get("password");

AdminLogin curAdmin = curAdminBO.findByName(userId, pwd);

ActionMessages errors = new ActionMessages();
HttpSession session = request.getSession(true);

if(curAdmin != null)
{
session.setAttribute("adminLogin", curAdmin);

returnForward = mapping.findForward("success");
}
else
....
}
}

--------------
AdminLoginBO.java (part of it)

public class AdminLoginBO extends BaseLinkBO
{
private static DataSource dataSource;

AdminLoginBO(DataSource dataSource)
{
super(dataSource);
}

AdminLoginBO()
{
super();
}

public AdminLogin findByName(String aName, String aPwd)
throws EntityNotFoundException, SQLException
{
Connection conn = dataSource.getConnection();
try
{
AdminLogin curAdmin = (new AdminLoginDAO(conn)).findByName(aName, aPwd);
conn.commit();
return curAdmin;
} catch (EntityNotFoundException e) {
conn.rollback();
throw e;
} catch (SQLException e) {
conn.rollback();
throw e;
} finally {
conn.close();
}
}
....
}

--------------------
BaseLinkBO.java (part of it)

public abstract class BaseLinkBO
{
protected final DataSource dataSource;

protected BaseLinkBO(DataSource dataSource)
{
this.dataSource = dataSource;
}

protected BaseLinkBO()
{
this.dataSource = ServiceLocator.getInstance().getDataSource();
}

......

}

-----------
ServiceLocator.java

public class ServiceLocator
{

private static ServiceLocator instance;
private DataSource dataSource;

static {
instance = new ServiceLocator();
}

private ServiceLocator () {
Context context = null;

try {
context = new InitialContext();
dataSource = (DataSource) context.lookup("java:/comp/env/jdbc/myDataSource");
}
catch (NamingException e) {
System.out.println(e.toString());
}
}

public static ServiceLocator getInstance() {
return instance;
}

public DataSource getDataSource() {
return dataSource;
}

}
[ October 01, 2007: Message edited by: northcloud ]
16 years ago
JSP