This week's book giveaway is in the OCMJEA forum.
We're giving away four copies of OCM Java EE 6 Enterprise Architect Exam Guide and have Paul Allen & Joseph Bambara on-line!
See this thread for details.
The moose likes Struts and the fly likes Very basic question Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Very basic question" Watch "Very basic question" New topic
Author

Very basic question

Madhuri Dhahiwal
Greenhorn

Joined: Jun 17, 2006
Posts: 2
Dear All

I have very simple problem. I am not able to get <bean:message key="title.login"/> working.

I have following configuration.

struts 1.2.9
Tomcat 5.5

My web.xml is like

<?xml version="1.0" encoding="ISO-8859-1"?>

<!DOCTYPE web-app
PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.2//EN"
"http://java.sun.com/j2ee/dtds/web-app_2_2.dtd">

<web-app>
<display-name>Struts Blank Application</display-name>

<!-- Standard Action Servlet Configuration (with debugging) -->
<servlet>
<servlet-name>action</servlet-name>
<servlet-class>org.apache.struts.action.ActionServlet</servlet-class>
<init-param>
<param-name>config</param-name>
<param-value>/WEB-INF/struts-config.xml</param-value>
</init-param>
<init-param>
<param-name>debug</param-name>
<param-value>2</param-value>
</init-param>
<init-param>
<param-name>detail</param-name>
<param-value>2</param-value>
</init-param>
<load-on-startup>2</load-on-startup>
</servlet>


<!-- Standard Action Servlet Mapping -->
<servlet-mapping>
<servlet-name>action</servlet-name>
<url-pattern>*.do</url-pattern>
</servlet-mapping>


<!-- The Usual Welcome File List -->
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>


<!-- Struts Tag Library Descriptors -->
<taglib>
<taglib-uri>/tags/struts-bean</taglib-uri>
<taglib-location>/WEB-INF/struts-bean.tld</taglib-location>
</taglib>

<taglib>
<taglib-uri>/tags/struts-html</taglib-uri>
<taglib-location>/WEB-INF/struts-html.tld</taglib-location>
</taglib>

<taglib>
<taglib-uri>/tags/struts-logic</taglib-uri>
<taglib-location>/WEB-INF/struts-logic.tld</taglib-location>
</taglib>

<taglib>
<taglib-uri>/tags/struts-nested</taglib-uri>
<taglib-location>/WEB-INF/struts-nested.tld</taglib-location>
</taglib>

<taglib>
<taglib-uri>/tags/struts-tiles</taglib-uri>
<taglib-location>/WEB-INF/struts-tiles.tld</taglib-location>
</taglib>

</web-app>

My strus-config.xml is like

<?xml version="1.0" encoding="ISO-8859-1" ?>

<!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>

<!-- ========== Form Bean Definitions ============ -->
<form-beans>
<form-bean name="login" type="org.apache.struts.validator.DynaValidatorForm" />
<form-property name="userId" type="java.lang.String" />
<form-property name="passWord" type="java.lang.String" />

</form-beans>


<plug-in className="org.apache.struts.validator.ValidatorPlugIn">
<set-property property="pathnames"
value="/WEB-INF/validator-rules.xml,
/WEB-INF/validation.xml"/>
</plug-in>

<!-- ========== Global Forward Definitions ========= -->
<global-forwards>
</global-forwards>


<!-- ========== Action Mapping Definitions ======== -->
<action-mappings>
<action
path="/login"
type="test.struts.LoginAction" >

<forward name="valid" path="/jsp/MainMenu.jsp" />
<forward name="invalid" path="/jsp/LoginView.jsp" />
</action>
</action-mappings>

</struts-config>

My jsp goes like this

<!-- LoginView.jsp -->

<%@ taglib uri="/tags/struts-html" prefix="html"%>
<%@ taglib uri="/tags/struts-bean" prefix="bean"%>
<HTML>
<HEAD>
<TITLE>
<bean:message key="title.login"/>
</TITLE>
</HEAD>
<BODY><p> This is very very bad.
<bean:message key="title.login"/>
</BODY>
</HTML>

I just wanted <baen:message>

I get following error

exception

org.apache.jasper.JasperException: Exception in JSP: /jsp/First.jsp:8

5: <HTML>
6: <HEAD>
7: <TITLE>
8: <bean:message key="title.login"/>
9: </TITLE>
10: </HEAD>
11: <BODY><p> This is very very bad.


Stacktrace:
org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:504)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:375)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:314)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:264)
javax.servlet.http.HttpServlet.service(HttpServlet.java:860)

My message.properties is like

button.submit=Send for Verification
error.no.userId=<li>User ID is a required field</li>
error.no.passWord=<li>Password is a required field</li>
error.invalid.login=<li>The User ID and/or Password are invalid. Please try again.</li>
errors.footer=</ul><hr>
errors.header=<h3><font color="red">Validation Error</font></h3>You must correct the following error(s) before proceeding:<ul>
label.userId=User ID
label.passWord=Password
heading.login=<H2>Enter your user information</H2>
title.login=Login Screen
title.mainmenu=Welcome
heading.mainmenu=<H1>Welcome!</H1>
label.userType=<H2>You are authorized to use this system as a</H2>
errors.required={0} is required.<br>
errors.minlength={0} cannot be less than {1} characters<br>

Where am I going wrong? I think taglibs entries are finding the required tld files in my WEB-INF but <bean:message> not working? Please guide.

Madhuri Dhahiwal
Merrill Higginson
Ranch Hand

Joined: Feb 15, 2005
Posts: 4864
From what you've shown us of your struts-config.xml file, you haven't configured the message resources. You need an entry like this:

<message-resources parameter="message"/>

You also need to make sure your message.properties file is in /WEB-INF/classes.

This link has a lot of good information about all aspects of messages in Struts.


Merrill
Consultant, Sima Solutions
Madhuri Dhahiwal
Greenhorn

Joined: Jun 17, 2006
Posts: 2
Thanks it is really working now.

Madhuri
shruthip prashu
Greenhorn

Joined: Jul 19, 2006
Posts: 5
Am using jsp and display tag. when am using java script its giving error.
Error:
could no process the requestorg.apache.jasper.JasperException: /web/viewdata.jsp(5,5) Invalid standard action

Can anyone help me.. Thanks in advance
 
Consider Paul's rocket mass heater.
 
subject: Very basic question