my dog learned polymorphism*
The moose likes Struts and the fly likes unable to run the file Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "unable to run the file" Watch "unable to run the file" New topic
Author

unable to run the file

pramod talekar
Ranch Hand

Joined: Apr 26, 2010
Posts: 316

Hello,

Could you please advise on this:

I'm using Eclipse to create a Struts app.

I have two jsp files :

1. ProductForm.jsp

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Add Product</title>
</head>
<body>

<div id="global">

<h3>Add a product</h3>
<form method="post" action="Product_save.action">
<table>
<tr>
<td>Product Name:</td>
<td><input type="text" name="productName"></td>
</tr>

<tr>
<td>Description:</td>
<td><input type="text" name="description"></td>
</tr>

<tr>
<td>Price :</td>
<td><input type="text" name="price"></td>
</tr>

<tr>
<td><input type="reset"></input></td>
<td><input type="submit" value="Add Product"></td>
</tr>
</table>
</form>
</div>

</body>
</html>


2. ProductDetails.jsp

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
<div id="global">

<h4>The Product has been saved.</h4>

<p>
<h5>Details:</h5>
Description: ${product.description};
<br></br>

Price: ${product.price
</div>
</body>
</html>

3. web.xml file

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaeehttp://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5">
<display-name>app02b</display-name>
<welcome-file-list>

<welcome-file>default.jsp</welcome-file>
</welcome-file-list>

<filter>
<filter-name>struts2</filter-name>
<filter-class>org.apache.struts2.dispatcher.FilterDispatcher</filter-class>
</filter>

<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>

</web-app>


4. struts.xml file

<?xml version="1.0" encoding="UTF-8"?>

<!DOCTYPE struts PUBLIC "-//Apache Software Foundation// DTD Struts Configuration 2.0//EN"
"http://struts.apache.org/dtds/struts-2.0 dtd">

<struts>
<package name="app02b" namespace="/" extends="struts-default">
<action name="Product_input">
<result>/jsp/ProductForm.jsp</result>
</action>

<action name="Product_save" class="app02b.Product">
<result>/jsp/ProductDetails.jsp</result>
</action>

</package>

</struts>


5.Product(An Action class)

package app02b;

import java.io.Serializable;

public class Product implements Serializable {

private String productName;
private String description;
private String price;

public String getProductName()
{
return productName;
}

public String getDescription()
{
return description;
}

public String getPrice()
{
return price;
}

public void setDescription(String description)
{
this.description = description;
}

public void setPrice(String p)
{
this.price = p;
}

public void setProductName(String p)
{
this.productName = p;
}

public String execute()
{
return "success";
}

}


----------------------
Could you please tell me where to place struts.xml file in Eclipse, currently it is in WEB-INF/lib (same as web.xml).
Both jsps' are under Web-content folder, Product class is under src folder.

If I run the application, I get 404 error.

Eclipse shows this path :http://localhost:8080/app02b/

I tried writing ProductForm.jsp after app02b/ but it shows the same result.


Thanks,
Pramod
vanlalhmangaiha khiangte
Ranch Hand

Joined: Sep 11, 2006
Posts: 170
Hi
Put it under the src folder ...


regards,
Vanlal
pramod talekar
Ranch Hand

Joined: Apr 26, 2010
Posts: 316

Hi Vanlal,

I put up struts.xml file under src folder in app02b package.
But I'm still getting 404 error.

I need ProductForm.jsp to appear once I click on Run.
I haven't put anything under <welcome file> tag and manually writing ProductForm at the end of the url. (app02b/ProductForm)

Please advise.

Thanks,
Pramod
pramod talekar
Ranch Hand

Joined: Apr 26, 2010
Posts: 316

I've taken out struts.xml of app02b package. It is under src folder now, outside the package.

Also tried this out : http://localhost:8080/app02b/jsp/ProductForm

but it's showing same 404 error (Resource not available).
Prashant Dasari
Greenhorn

Joined: Oct 28, 2010
Posts: 6
I need ProductForm.jsp to appear once I click on Run.
I haven't put anything under <welcome file> tag and manually writing ProductForm at the end of the url.


If you don't put anything in <welcome file> tag how can you expect ProductForm.jsp to show up when you click run?

I've taken out struts.xml of app02b package.


I don't understand this. I think app02b is the name of your project. Under this project You will find Java Resources:src. This folder must contain struts.xml.
pramod talekar
Ranch Hand

Joined: Apr 26, 2010
Posts: 316

Hi Prashant,

Thanks for the reply.

see this :

<struts>
<package name="app02b" namespace="/" extends="struts-default">
<action name="Product_input">
<result>/jsp/ProductForm.jsp</result>
</action>

<action name="Product_save" class="app02b.Product">
<result>/jsp/ProductDetails.jsp</result>
</action>

I have a package as well with the same name app02b and Product is an action class put inside it.


I'm new to Struts, and I've not mentioned anything under welcome file, but I'm adding the jsp file name to the url after running first.
So I guess, it should show me the result.

Please advise.
pramod talekar
Ranch Hand

Joined: Apr 26, 2010
Posts: 316

Hi Prashant,

This is the structure :

src/ app02b(package name) / Product(class)

src/struts.xml


WEB-INF/lib/web.xml
WEB-INF/ ProductForm.jsp
WEB-INF/ProductDetails.jsp
Prashant Dasari
Greenhorn

Joined: Oct 28, 2010
Posts: 6
WEB-INF/lib/web.xml


web.xml must be in WEB-INF and not WEB-INF/lib
pramod talekar
Ranch Hand

Joined: Apr 26, 2010
Posts: 316

Oh- right !.
It's the same.. mentioned it by mistake..

sorry for that..
Prashant Dasari
Greenhorn

Joined: Oct 28, 2010
Posts: 6
Do you still get 404 error?

WEB-INF/ ProductForm.jsp
WEB-INF/ProductDetails.jsp


Put the files ProductForm.jsp and ProductDetails.jsp in WebContent. Right click on ProductForm.jsp and Run as -> run on server. Select the server -> remove all except the project. Now you should atleast see the jsp without the error.
Jaimesh M Ponkia
Greenhorn

Joined: Nov 24, 2010
Posts: 21
Make sure you have the following checks done before you run the project:

1. All the class files in source folder and the same has been configured in the build properties.
2. JSP pages in WebContent folder
3. web.xml file in WEB-INF root
4. struts-config.xml anywhere in WEB-INF folder.
5. Configure the path for struts-config.xml in web.xml
6. Welcome file in web.xml
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: unable to run the file