aspose file tools*
The moose likes Struts and the fly likes error while running my struts application Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "error while running my struts application" Watch "error while running my struts application" New topic
Author

error while running my struts application

sreejith parambath
Greenhorn

Joined: Nov 19, 2006
Posts: 8
hi all,
i am new to struts and i have developed my application something like this.

i have a login page named Login.jsp, which has a corresponding ActionForm and Action Class, the web.xml and struts-config.xml are also there in addition to the Application Resources.properties file. the application properties file and the .java files are in a package called mystrutspack.

the code snippets is as follows:-

Login.jsp
---------


<%@ page language="java" import="java.util.*" %>
<%@ taglib uri="http://jakarta.apache.org/struts/tags-html" prefix="html" %>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">

<title>My JSP 'Lgoin.jsp' starting page</title>

<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">

<!--
<link rel="stylesheet" type="text/css" href="styles.css">
-->
</head>

<body>
<html:form name="EmpForm" type="strutspack.EmployeeForm" action="/EmpLogin"> <br>
<table border=0 align=center bgcolor="ivory">
<tr>
<td><bean:message key="loginpage.empfirstname"/>
<td><html:text property="firstname"/>
<tr>
<td><bean:message key="loginpage.emplastname"/>
<td><html:text property="lastname"/>

<tr>
<td><bean:message key="loginpage.empdepartment"/>
<td><html:text property="department"/>
<tr>
<td><html:submit property="Submit"/>
<td><html:reset property="Reset"/>
</table>
</html:form>
<%

if((request.getAttribute("myempfname"))!=null&&(request.getAttribute("myemplname"))!=null)
{

out.println("The Firstname entered by you is "+request.getAttribute("myempfname")+"."+"\\n");
out.println("\nThe Lastname entered by you is "+request.getAttribute("myemplname")+"."+"\n");
out.println("\nThe Department entered by you is "+request.getAttribute("myempdept")+"."+"\n");
}

%>

</body>
</html>


EmployeeAction.java
-------------------

package strutspack;
import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts.action.*;

public class EmployeeAction extends Action
{
public EmployeeAction()
{
}

public ActionForward execute(ActionMapping map, ActionForm form, HttpServletRequest req, HttpServletResponse res)
throws IOException, ServletException
{

String targetvalue = "hurray";
if(form != null)
{
EmployeeForm ourForm = (EmployeeForm)form;
String fname = ourForm.getFirstname();
String lname = ourForm.getLastname();
String dept=ourForm.getDepartment();

if(!fname.equals("null") && !lname.equals("null")&&!dept.equals("null"))
{
req.setAttribute("myempfname", new String(fname));
req.setAttribute("myemplname", new String(lname));
req.setAttribute("myempdept",new String(dept));
} else
{
targetvalue = "oh no";
}
}
return map.findForward(targetvalue);
}
}


EmployeeForm.java
-----------------

package strutspack;
import javax.servlet.http.HttpServletRequest;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionMapping;

public class EmployeeForm extends ActionForm
{
private String firstName;
private String lastName;
private String department;

//setting the firstname
public void setFirstname(String firstname)
{
this.firstName=firstname;
}
public String getFirstname()
{
return firstName;
}

//setting the lastname
public void setLastname(String lastname)
{
this.lastName=lastname;
}
public String getLastname()
{
return lastName;
}

//setting the department
public void setDepartment(String department)
{
this.department=department;
}
public String getDepartment()
{
return department;
}
}

ApplicationResources.properties file
------------------------------------

# Resources for parameter 'strutspack.ApplicationResources'
# Project P/TryStrutsProject
loginpage.empfirstname= Employee's First Name
loginpage.emplastname=Enter Employee's Last Name
loginpage.empdepartment=Enter Employee's Depatment


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

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE struts-config PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 1.1//EN" "http://jakarta.apache.org/struts/dtds/struts-config_1_1.dtd">
<struts-config>
<data-sources />
<form-beans >
<form-bean name="EmpForm" type="strutspack.EmployeeForm"/>
</form-beans>
<global-exceptions />
<global-forwards >
</global-forwards>
<action-mappings >
<action path="/EmpLogin" name="EmpForm" type="strutspack.EmployeeAction">
<forward name="hurray" path="/Login.jsp"/>
</action>
</action-mappings>
<message-resources parameter="strutspack.ApplicationResources" />
</struts-config>


i m getting a error message something like this:-

the login page is coming but the values from the application resources file is not being read and it shows a blank label.


can anyone help me in this

sreejith


Merrill Higginson
Ranch Hand

Joined: Feb 15, 2005
Posts: 4864
Make sure the ApplicationResources.properties file exists in your WEB-INF/classes/strutspack directory.


Merrill
Consultant, Sima Solutions
sreejith parambath
Greenhorn

Joined: Nov 19, 2006
Posts: 8
i am using eclipse 3.1 and the applicationresources.properties file exists in the /src/strutspack directory.
Merrill Higginson
Ranch Hand

Joined: Feb 15, 2005
Posts: 4864
It's fine to put a copy of the properties file in the source directory, but Struts will not read it from there. It must be copied to your WEB-INF/classes directory along will all your java class files. I believe that Eclipse will automatically copy properties files from the source directory to the binaries directory, but you need to verify this. Make sure that the file exists in WEB-INF/classes/strutspack.
prasanth jalasutram
Greenhorn

Joined: Dec 15, 2004
Posts: 6
hi,

if you are using weblogic8.1 you may use this alternative.

As said by others it should be some problem that your properties file is not loaded in classes folder.recheck your .war file or your files.

but alternately you may use <i18> tag only if you are using weblogic8.1 version.
<%
String language = "en_us";
%>
<i18n:localize language="<%=language%>" bundleName="Messages"/>
<html>
<body>
<i18n:getMessage messageName="greeting"/>
</body>
</html>

Hope it helps you.

thanks
prasanth jalasutram
 
Consider Paul's rocket mass heater.
 
subject: error while running my struts application