Struts : resource messages from el in jsp
Hi all,
is there a way to access the resource messages directly from el, like within the test attribute of tag c:when
At the present i have to create a var using core tag library like this :
<c:set var="addAction">
<bean:message key="button.add"/>
</c:set>and then use the var
<c:choose>
<c:when test="${myFormBean.action==addAction}">
action1
</c:when>
<c:otherwise>
action2
</c:otherwise>
</c:choose>
For some strange reason, you cannot call the method close() on a non-existant database handle. For example...
Connection conn = DriverManager.getConnection( url, username, password );
conn = null;
conn.close();will result in a null pointer error. Sometimes if you attempt to create a connection and you don't get one, conn will be null anyway rather than returning a specific error message.
As a general rule of thumb, it's always a good idea to...
public void closeSession( Connection conn ) {
if ( conn != null ) {
conn.close();
}or even...
try {
conn.close();
} catch ( Exception e ) { }Because if the connection no longer exists, then it serves the same practical purpose as closing the connection as far as your program is concerned.
Similar Messages
-
Error message from servlet to jsp
Hi again,
I have servlet and check error on this servlet then i would like
to send error message to jsp page.Every error message will send to
same JSP page.So JSP must receive message from Servlet.Can i do this?
Please give me details and some sourcecode.I will appreciate for your helps.you could do something like this..
request.setAttribute("error", stringErrormessage);
Then in the jsp just do
<%= request.getAttribute("error") %>
That will print an errormessage.
Basically, by setting anything on the request and then redirecting to that page you cn display it...
//Johan -
How to send a message from Servlet to JSP
Dear all,
I have JSP, with JavaScript (AJAX). If the user click on the button, the text will be sent to a Servlet parsed by doGet() and the user get a response to his input, without reloading a page.
How can I send a message to the users (JSP) from Servlet, if he didn't clicked any button and to other visitor of the page also? Is it possible? I think like a chat, the server sends a message to all users who are subscribed.
I don't know, what should I get from user, maybe session, that I could send him personal or common messages in his textarea. I should also invoke some JavaScript function to update his page. I have met some chats, you don't do nothing and get messages. It is also without a JavaScript timer, which invokes doGet() method. Asynchronous, only when there is a message.
Please help me with a problem.
Thanks in advance.Hai ,
You can send any message through response.sendRedirect();
here is the coding try it
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class SimpleCounter extends HttpServlet {
public void doGet(HttpServletRequest req, HttpServletResponse res)
throws ServletException, IOException {
res.setContentType("text/plain");
PrintWriter out = res.getWriter();
String username="java";
res.sendRedirect("http://localhost:8080/yourprojectname/jspfile.jsp?username="+username);
} -
Message bundles accessed from JSF and JSP pages
Hello, everybody!
I'm developing a localized JSF application. It is working pretty well until now.
These are my message files:
mensagens.properties
mensagens_en_US.propertiesThis is how they're configured in faces-config.xml:
<application>
<resource-bundle>
<base-name>br.urca.www.biblioteca.web.mensagens</base-name>
<var>msg</var>
</resource-bundle>
</application>And this is how I access the messages in a page:
<h:outputText value="#{msg.titulo}" />Nothing new until now. But now there was a need for me to have a raw jsp page in
my web application. This page is displaying ok but I also need to access the
message bundles as I'm able to access in the normal jsp with the JSF components.
As you should know I can't use something like the above code with an +<h:outputText>+
to access the messages because this is a JSF component and I'll not be able to use
JSF components with this raw jsp page.
So, my question is: how do I access my localized messages from a raw jsp page? I
suppose there should be a way to do this, but unfortunately I started programming
to the web world in Java with JSF, not JSP, so I don't know how to do this with
JSP.
Thank you very much.
MarcosBalusC wrote:
Just include [jstl-1.2.jar|https://maven-repository.dev.java.net/repository/jstl/jars/] in your classpath and define the fmt taglib in your JSP. Nothing more is needed.
Hello, BalusC. Thank you for your help. We're almost there. After I have included the jstl-1.2.jar you provided me I can use the fmt tag and access message bundles from my raw jsp page (even though I had to provide other message bundles instead of the ones that I use in the other jsf pages, but it's better than nothing).
Now there just on problem to be fixed. The jsp page is not aware when I change the locale of my application. I change this locale in a jsf page.
I have this component:
<h:selectOneMenu value="#{pesquisaAcervo.idiomaAplicacao}"
valueChangeListener="# {pesquisaAcervo.idiomaAplicacaoMudado}" onchange="submit();">
<f:selectItems value="#{pesquisaAcervo.idiomasAplicacao}" />
</h:selectOneMenu>that calls this event in my backing bean class:
public void idiomaAplicacaoMudado(ValueChangeEvent e)
fIdiomaAplicacao.liberarItens();
Idioma idioma = Idioma.deString(e.getNewValue().toString());
// This line is for JSF
FacesContext.getCurrentInstance().getViewRoot().setLocale(idioma.localidade());
// This line is for Tiles
FacesContext.getCurrentInstance().getExternalContext().getSessionMap().
put(org.apache.tiles.locale.impl.DefaultLocaleResolver.LOCALE_KEY, idioma.localidade());
}So, do I have to include another line in the idiomaAplicacaoMudado event above in order for the jsp page load the correct resource bundle? Or what else do I have to do?
Thank you.
Marcos -
How to display Image as Error instead of Error Message from Resource Bundle
hi,
I want to display images as error instead of error message from Application Properties in struts1.1
Ex:
I want to prompt a user to type password length min. of 6 char. If failed, need to show simple image as error rather
"Length should be min. 6".
reagrds
parthiban.BalusC wrote:
RahulSharna wrote:
in the respective resource bundle modify the value by something was below
error.password.length=<img src="/images/password-Length.gif" alt="Password Length Issue" align="center"/>
OK, it apparently allows HTML in error messages.Yes struts allows it :) -
Hi All,
I am getting the following error.. while running a simple application in struts.
Cannot find message resources under key org.apache.struts.action.MESSAGE ?
As I have searched in google but could not find the concreate example so please help and give me a proper answer..
my struts-config.xml file is as .....
<code>
<?xml version="1.0" encoding="ISO-8859-1" ?>
<!DOCTYPE struts-config PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 1.0//EN"
"http://jakarta.apache.org/struts/dtds/struts-config_1_0.dtd">
<struts-config>
<!-- ========== Form Bean Definitions ============ -->
<form-beans>
<form-bean name="login" type="test.struts.LoginForm" />
</form-beans>
<!-- ========== Global Forward Definitions ========= -->
<global-forwards>
</global-forwards>
<!-- ========== Action Mapping Definitions ======== -->
<action-mappings>
<action
path="/login"
type="test.struts.LoginAction"
name="login"
input="/jsp/LoginView.jsp"
validate="true">
<forward name="valid" path="/jsp/MainMenu.jsp" />
<forward name="invalid" path="/jsp/LoginView.jsp" />
</action>
</action-mappings>
<message-resources null="false" parameter="test.struts.MessageResources"/>
</struts-config>
</code>
And my LoginView.jsp file is as:
<code>
<!-- LoginView.jsp -->
<%@ taglib uri="/struts/WEB-INF/struts-html.tld" prefix="html" %>
<%@ taglib uri="/struts/WEB-INF/struts-bean.tld" prefix="bean" %>
<%@ taglib uri="/struts/WEB-INF/struts-logic.tld" prefix="struts" %>
<HTML>
<HEAD><TITLE><bean:message key="title.login" /></TITLE></HEAD>
<BODY>
<bean:message key="heading.login" />
<html:errors />
<html:form action="/login">
<p>
<bean:message key="label.userId" />:
<html:text property="userId" size="10" />
<br>
<bean:message key="label.passWord" />:
<html:password property="passWord" size="10" />
<br><br>
<html:submit>
<bean:message key="button.submit" />
</html:submit>
</html:form>
</BODY>
</HTML>
</code>
MessageResources.properties is as :
<code>
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>
</code>
Please reply soon.
Thanks in advance
AmitindiaHi All,
I am getting the following error.. while running a simple application in struts.
Cannot find message resources under key org.apache.struts.action.MESSAGE ?
As I have searched in google but could not find the concreate example so please help and give me a proper answer.. my struts-config.xml file is as .....
<?xml version="1.0" encoding="ISO-8859-1" ?> <!DOCTYPE struts-
config PUBLIC "-//Apache Software Foundation//DTD Struts
Configuration 1.0//EN" "http://jakarta.apache.org/struts/dtds/struts-
config_1_0.dtd"> <struts-config> <!-- ========== Form Bean
Definitions ============ --> <form-beans> <form-bean name="login"
type="test.struts.LoginForm" /> </form-beans> <!-- ========== Global Forward Definitions ========= --> <global-forwards> </global-
forwards> <!-- ========== Action Mapping Definitions ======== --> <action-mappings> <action path="/login" type="test.struts.LoginAction" name="login" input="/jsp/LoginView.jsp" validate="true"> <forward name="valid" path="/jsp/MainMenu.jsp" /> <forward name="invalid" path="/jsp/LoginView.jsp" /> </action> </action-mappings> <message-resources null="false" parameter="test.struts.MessageResources"/> </struts-config>
And my LoginView.jsp file is as:
<!-- LoginView.jsp --> <%@ taglib uri="/struts/WEB-INF/struts-html.tld" prefix="html" %> <%@ taglib uri="/struts/WEB-INF/struts-bean.tld" prefix="bean" %> <%@ taglib uri="/struts/WEB-INF/struts-logic.tld" prefix="struts" %> <HTML> <HEAD><TITLE><bean:message key="title.login" /></TITLE></HEAD> <BODY> <bean:message key="heading.login" /> <html:errors /> <html:form action="/login">
<bean:message key="label.userId" />: <html:text property="userId" size="10" /> <br> <bean:message key="label.passWord" />: <html:password property="passWord" size="10" /> <br><br> <html:submit> <bean:message key="button.submit" /> </html:submit> </html:form> </BODY> </HTML>
MessageResources.properties is as :
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>
Please reply soon. Thanks in advance Amitindia -
Error when parsing SOAP message from JSP
i write a class to call SOAP message from a servlet on jdev 1013
when i run the class alone it works fine
soapMessage = this.buildSOAPMessagee();
ByteArrayOutputStream output = new ByteArrayOutputStream();
soapMessage.writeTo(output);
SOAPConnectionFactory connf = SOAPConnectionFactory.newInstance();
SOAPConnection conn = connf.createConnection();
SOAPMessage smsg= conn.callsoapMessage, "http://190.0.0.16:8988/mmsc/httpReceiver");
smsg.writeTo(out);
but when running same class same method from jsp page...i have Exception
javax.xml.soap.SOAPException: Unable to get header stream in saveChanges at oracle.j2ee.ws.saaj.soap.MessageImpl.saveChangesMimeEncoded(MessageImpl.java:576) at oracle.j2ee.ws.saaj.soap.MessageImpl.saveChanges(MessageImpl.java:622) at oracle.j2ee.ws.saaj.soap.MessageImpl.saveChanges(MessageImpl.java:686) at oracle.j2ee.ws.saaj.soap.MessageImpl.writeTo(MessageImpl.java:702) at test.test2.ret(test2.java:341) at untitled1.jspService(_untitled1.java:45) [untitled1.jsp] at com.orionserver[Oracle Containers for J2EE 10g (10.1.3.0.0) ].http.OrionHttpJspPage.service(OrionHttpJspPage.java:60) at oracle.jsp.runtimev2.JspPageTable.service(JspPageTable.java:416) at oracle.jsp.runtimev2.JspServlet.internalService(JspServlet.java:478) at oracle.jsp.runtimev2.JspServlet.service(JspServlet.java:401) at javax.servlet.http.HttpServlet.service(HttpServlet.java:856) at com.evermind[Oracle Containers for J2EE 10g (10.1.3.0.0) ].server.http.ServletRequestDispatcher.invoke(ServletRequestDispatcher.java:719) at com.evermind[Oracle Containers for J2EE 10g (10.1.3.0.0) ].server.http.ServletRequestDispatcher.forwardInternal(ServletRequestDispatcher.java:376) at com.evermind[Oracle Containers for J2EE 10g (10.1.3.0.0) ].server.http.HttpRequestHandler.doProcessRequest(HttpRequestHandler.java:870) at com.evermind[Oracle Containers for J2EE 10g (10.1.3.0.0) ].server.http.HttpRequestHandler.processRequest(HttpRequestHandler.java:451) at com.evermind[Oracle Containers for J2EE 10g (10.1.3.0.0) ].server.http.HttpRequestHandler.serveOneRequest(HttpRequestHandler.java:218) at com.evermind[Oracle Containers for J2EE 10g (10.1.3.0.0) ].server.http.HttpRequestHandler.run(HttpRequestHandler.java:119) at com.evermind[Oracle Containers for J2EE 10g (10.1.3.0.0) ].server.http.HttpRequestHandler.run(HttpRequestHandler.java:112) at oracle.oc4j.network.ServerSocketReadHandler$SafeRunnable.run(ServerSocketReadHandler.java:260) at oracle.oc4j.network.ServerSocketAcceptHandler.procClientSocket(ServerSocketAcceptHandler.java:230) at oracle.oc4j.network.ServerSocketAcceptHandler.access$800(ServerSocketAcceptHandler.java:33) at oracle.oc4j.network.ServerSocketAcceptHandler$AcceptHandlerHorse.run(ServerSocketAcceptHandler.java:831) at com.evermind[Oracle Containers for J2EE 10g (10.1.3.0.0) ].util.ReleasableResourcePooledExecutor$MyWorker.run(ReleasableResourcePooledExecutor.java:298) at java.lang.Thread.run(Thread.java:595)Caused by: java.io.IOException: SOAP exception while trying to externalize: Error parsing envelope: (1, 1) Start of root element expected. at oracle.j2ee.ws.saaj.soap.SOAPPartImpl.getContentAsStream(SOAPPartImpl.java:220) at oracle.j2ee.ws.saaj.soap.MessageImpl.getHeaderBytes(MessageImpl.java:522) at oracle.j2ee.ws.saaj.soap.MessageImpl.saveChangesMimeEncoded(MessageImpl.java:574) ... 23 moreCaused by: javax.xml.soap.SOAPException: Error parsing envelope: (1, 1) Start of root element expected. at oracle.j2ee.ws.saaj.soap.soap11.SOAPImplementation11.createEnvelope(SOAPImplementation11.java:104) at oracle.j2ee.ws.saaj.soap.SOAPPartImpl.getEnvelope(SOAPPartImpl.java:76) at oracle.j2ee.ws.saaj.soap.SOAPPartImpl.getContentAsStream(SOAPPartImpl.java:215) ... 25 moreCaused by: oracle.xml.parser.v2.XMLParseException: Start of root element expected. at oracle.xml.parser.v2.XMLError.flushErrors1(XMLError.java:320) at oracle.xml.parser.v2.NonValidatingParser.parseRootElement(NonValidatingParser.java:333) at oracle.xml.parser.v2.NonValidatingParser.parseDocument(NonValidatingParser.java:295) at oracle.xml.parser.v2.XMLParser.parse(XMLParser.java:201) at oracle.j2ee.ws.saaj.soap.soap11.SOAPImplementation11.createEnvelope(SOAPImplementation11.java:78) ... 27 more
dose anybody can help why that happend when running the code from JSPi write a class to call SOAP message from a servlet on jdev 1013
when i run the class alone it works fine
soapMessage = this.buildSOAPMessagee();
ByteArrayOutputStream output = new ByteArrayOutputStream();
soapMessage.writeTo(output);
SOAPConnectionFactory connf = SOAPConnectionFactory.newInstance();
SOAPConnection conn = connf.createConnection();
SOAPMessage smsg= conn.callsoapMessage, "http://190.0.0.16:8988/mmsc/httpReceiver");
smsg.writeTo(out);
but when running same class same method from jsp page...i have Exception
javax.xml.soap.SOAPException: Unable to get header stream in saveChanges at oracle.j2ee.ws.saaj.soap.MessageImpl.saveChangesMimeEncoded(MessageImpl.java:576) at oracle.j2ee.ws.saaj.soap.MessageImpl.saveChanges(MessageImpl.java:622) at oracle.j2ee.ws.saaj.soap.MessageImpl.saveChanges(MessageImpl.java:686) at oracle.j2ee.ws.saaj.soap.MessageImpl.writeTo(MessageImpl.java:702) at test.test2.ret(test2.java:341) at untitled1.jspService(_untitled1.java:45) [untitled1.jsp] at com.orionserver[Oracle Containers for J2EE 10g (10.1.3.0.0) ].http.OrionHttpJspPage.service(OrionHttpJspPage.java:60) at oracle.jsp.runtimev2.JspPageTable.service(JspPageTable.java:416) at oracle.jsp.runtimev2.JspServlet.internalService(JspServlet.java:478) at oracle.jsp.runtimev2.JspServlet.service(JspServlet.java:401) at javax.servlet.http.HttpServlet.service(HttpServlet.java:856) at com.evermind[Oracle Containers for J2EE 10g (10.1.3.0.0) ].server.http.ServletRequestDispatcher.invoke(ServletRequestDispatcher.java:719) at com.evermind[Oracle Containers for J2EE 10g (10.1.3.0.0) ].server.http.ServletRequestDispatcher.forwardInternal(ServletRequestDispatcher.java:376) at com.evermind[Oracle Containers for J2EE 10g (10.1.3.0.0) ].server.http.HttpRequestHandler.doProcessRequest(HttpRequestHandler.java:870) at com.evermind[Oracle Containers for J2EE 10g (10.1.3.0.0) ].server.http.HttpRequestHandler.processRequest(HttpRequestHandler.java:451) at com.evermind[Oracle Containers for J2EE 10g (10.1.3.0.0) ].server.http.HttpRequestHandler.serveOneRequest(HttpRequestHandler.java:218) at com.evermind[Oracle Containers for J2EE 10g (10.1.3.0.0) ].server.http.HttpRequestHandler.run(HttpRequestHandler.java:119) at com.evermind[Oracle Containers for J2EE 10g (10.1.3.0.0) ].server.http.HttpRequestHandler.run(HttpRequestHandler.java:112) at oracle.oc4j.network.ServerSocketReadHandler$SafeRunnable.run(ServerSocketReadHandler.java:260) at oracle.oc4j.network.ServerSocketAcceptHandler.procClientSocket(ServerSocketAcceptHandler.java:230) at oracle.oc4j.network.ServerSocketAcceptHandler.access$800(ServerSocketAcceptHandler.java:33) at oracle.oc4j.network.ServerSocketAcceptHandler$AcceptHandlerHorse.run(ServerSocketAcceptHandler.java:831) at com.evermind[Oracle Containers for J2EE 10g (10.1.3.0.0) ].util.ReleasableResourcePooledExecutor$MyWorker.run(ReleasableResourcePooledExecutor.java:298) at java.lang.Thread.run(Thread.java:595)Caused by: java.io.IOException: SOAP exception while trying to externalize: Error parsing envelope: (1, 1) Start of root element expected. at oracle.j2ee.ws.saaj.soap.SOAPPartImpl.getContentAsStream(SOAPPartImpl.java:220) at oracle.j2ee.ws.saaj.soap.MessageImpl.getHeaderBytes(MessageImpl.java:522) at oracle.j2ee.ws.saaj.soap.MessageImpl.saveChangesMimeEncoded(MessageImpl.java:574) ... 23 moreCaused by: javax.xml.soap.SOAPException: Error parsing envelope: (1, 1) Start of root element expected. at oracle.j2ee.ws.saaj.soap.soap11.SOAPImplementation11.createEnvelope(SOAPImplementation11.java:104) at oracle.j2ee.ws.saaj.soap.SOAPPartImpl.getEnvelope(SOAPPartImpl.java:76) at oracle.j2ee.ws.saaj.soap.SOAPPartImpl.getContentAsStream(SOAPPartImpl.java:215) ... 25 moreCaused by: oracle.xml.parser.v2.XMLParseException: Start of root element expected. at oracle.xml.parser.v2.XMLError.flushErrors1(XMLError.java:320) at oracle.xml.parser.v2.NonValidatingParser.parseRootElement(NonValidatingParser.java:333) at oracle.xml.parser.v2.NonValidatingParser.parseDocument(NonValidatingParser.java:295) at oracle.xml.parser.v2.XMLParser.parse(XMLParser.java:201) at oracle.j2ee.ws.saaj.soap.soap11.SOAPImplementation11.createEnvelope(SOAPImplementation11.java:78) ... 27 more
dose anybody can help why that happend when running the code from JSP -
Send message from JSP page to Java message driven bean
Hi all
I'm using Jdev903.
I need to send a message from JSP page (Web Application) to Java Message Driven Bean.
* I created Message Driven Bean that named: MyMessageDrivenEJBBean
* I have configed jms.xml:
<topic-connection-factory name="ChatTopicConnectionFactory" location="jms/theTopicConnectionFactory"/>
<topic name="ChatTopic" location="jms/theTopic"/>
* In JSP page, my code is:
final Context ctx = new InitialContext();
// 1: Lookup ConnectionFactory via JNDI
TopicConnectionFactory factory =(TopicConnectionFactory)ctx.lookup("jms/theTopicConnectionFactory");
But trouble occurs is:
javax.naming.NameNotFoundException: jms/theTopicConnectionFactory not found
please help me!
thank a lot.Welcome to the Sun forums.
1. Please post your code using code tags, this formats it so that it is easier for people to read and understand it. Click on 'CODE' above the text area when posting.
2. As far as possible, please post an SSCCE
What have learnt about JSPs and servlets till now? Because reading the values submitted in a form is pretty much the base of all operations. I suggest you Google for [servlet tutorials|http://www.google.com/search?q=servlet+tutorial] and [JSP tutorials|http://www.google.com/search?q=jsp+tutorial] and go through them thoroughly. After you understand what is to be done and what options are available to you, if you still face problems, please feel free to post your queries here. But this isn't exactly a site for tutorials, especially since there are so many good ones already out there, that explain all this stuff in detail. There's no point in re-inventing the wheel.
Hints: [ServletRequest#getParameter()|http://java.sun.com/javaee/5/docs/api/javax/servlet/ServletRequest.html#getParameter(java.lang.String)] and [RequestDispatcher#forward|http://java.sun.com/javaee/5/docs/api/javax/servlet/RequestDispatcher.html] -
I stumbled across a funny little problem yesterday after a rash of users calling wanting to know why rooms were declining their meeting requests..
The rooms were declining for perfectly legitimate reasons.. Conflicts or no end date but the accept/decline reply messages the rooms were sending out had no details in the message body when viewed from Outlook 2010 or 2013.
If message preview is enabled in Outlook 2013 you can read a few lines of the body in the inbox view but it's still blank when you open the message.
Reading pane is also blank.
Opening the message from OWA or my phone shows the complete message body.
Very odd. It reminds me of the bug in Exchange 2013 CU2 where meeting invites to external users were sent blank unless they were sent as iCalendar.
Maybe this will resolve itself when I load SP1 in a few weeks.
Any one else seeing this?
We are running 2013 CU 3Hi Scott,
I have tested in my Exchange 2013 CU1 environment and I can reproduce your issue in Outlook online mode. Please check whether the problematic users are using Outlook Online mode in Outlook 2010 and Outlook 2013.
The issue doesn’t happen in OWA and Outlook Cached mode. Therefore, I recommend users can change their Outlook client to Cached mode as a workaround. To do it, we can:
Open Outlook, click File > Account Settings > Account Settings. Double-click the account, check Use Cached Exchange Mode > Next and finish it. Restart Outlook to use it in cached mode.
Thanks,
Winnie Liang
TechNet Community Support -
How to get error message on the same jsp
Hi guys,
I have a login.jsp page and I want an error message to be printed "login failed" in the same jsp page when the user enters the wrong credentials.
Any ideas on how to do that is highly appreciated.
Thanx in advance.sriIf you use struts it would have been a lot easier and better than only JSP.
In struts :
Add this line in ur JSP page
<html:errors/>
In ur Action servlet ex: LoginAction.java add thsi code extract in the appropriate position ...
ActionErrors errors = new ActionErrors();
errors.add(ActionErrors.GLOBAL_ERROR, new ActionError("error.user.wrong"));
if (!errors.isEmpty())
saveErrors(request, errors);
But in JSP do something like this:-
If authentication fails then post to the same JSP and put this code in the reqd position...
<%
String postFlag=request.getParameter("postFlag");
if(postFlag.equals("FAILED"))
%>
LOGIN FAILED
<%
%>
So for JSp simply set the request parameter (postFlag) to SUCCESSFUL/FAILED from your servlet. -
Struts can't display the input jsp page
Hello,
I'm using Struts 1.3.8 to construct a simple user registration system, in which the user could input his info (such as uuname and gpin, both are strings) in a jsp page, and after the submit, the system should go to a success page. However, somehow, when I access the url, it goes directly to the success page, but not stay at the input page.
Here is my {color:#ff0000}struts-xml.config{color}
bq. <?xml version="1.0" encoding="UTF-8"?> \\ <!DOCTYPE struts-config PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 1.3//EN" "http://struts.apache.org/dtds/struts-config_1_3.dtd"> \\ <struts-config> \\ <form-beans> \\ <form-bean name="{color:#ff0000}anotherUserForm{color}" type="com.visualbuilder.struts.beans.AnotherUser" /> \\ </form-beans> \\ <!-- Global Exceptions --> \\ <global-exceptions></global-exceptions> \\ <!-- Global Forwards --> \\ <global-forwards> \\ <forward name="success" path="success.jsp"/> </global-forwards> \\ <!-- Action Mappings --> \\ <action-mappings> \\ <action path="/{color:#ff0000}addanotheruser{color}" type="com.visualbuilder.struts.action.AddAnotherUserAction" name="{color:#ff0000}anotherUserForm{color}" attribute="user" input="{color:#ff0000}/addanotheruser.jsp{color}" cancellable="true"> \\ </action> \\ </action-mappings> \\ <!-- Message Resources --> \\ <message-resources \\ parameter="registration.resources.ApplicationResources" /> \\ </struts-config>
My action class is:
package com.visualbuilder.struts.action;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import com.visualbuilder.struts.beans.AnotherUser;
public class AddAnotherUserAction extends Action {
@Override
public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
if (isCancelled(request)) {
return mapping.findForward("welcome");
{color:#ff0000}AnotherUser anotherUser = (AnotherUser) form;{color}
System.out.println("UUName: " + anotherUser.getUuname() + "\tGPIN: " + anotherUser.getGpin());
{color:#ff0000}return mapping.findForward("success");{color}
My ActionForm class is:
package com.visualbuilder.struts.beans;
import javax.servlet.http.HttpServletRequest;
import org.apache.struts.action.ActionErrors;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionMapping;
public class AnotherUser extends ActionForm {
private static final long serialVersionUID = 1058901817587421984L;
private String uuname;
private String gpin;
public String getGpin() {
return gpin;
public void setGpin(String gpin) {
this.gpin = gpin;
public String getUuname() {
return uuname;
public void setUuname(String uuname) {
this.uuname = uuname;
@Override
public void reset(ActionMapping mapping, HttpServletRequest request) {
uuname = null;
gpin = null;
@Override
public ActionErrors validate(ActionMapping mapping, HttpServletRequest request) {
ActionErrors errors = new ActionErrors();
return errors;
The input jsp page is addanotheruser.jsp:
<%@ taglib uri="http://struts.apache.org/tags-html" prefix="html"%>
<%@ taglib uri="http://struts.apache.org/tags-bean" prefix="bean"%>
<%@ 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>Another User Registration</title>
</head>
<body>
<h1>Another User Registration</h1>
<html:errors />
<table>
{color:#ff0000}<html:form action="addanotheruser">{color}
<tr>
<td>UUName</td>
<td>{color:#ff0000}<html:text property="uuname"></html:text>{color}*</td>
</tr>
<tr>
<td>GPIN</td>
<td>{color:#ff0000}<html:text property="gpin"></html:text>{color}*</td>
</tr>
<tr>
<td><html:submit/></td>
<td><html:cancel/></td>
</tr>
</html:form>
</table>
</body>
</html>
Everytime I access http://localhost:9080/addanotheruser.do, it jumps to the success.jsp, but not stay at addanotheruser.jsp to wait for the user input, and in the server's console, I could see the output "UUName: null GPIN: null"
I've been stuck at this simple program for three days, could anybody help to find the errors? Thanks a lot.sorry, the post looks ugly. Does anybody know how to make the indent not disappear?
-
Subscribe OJMS Message from Java Client ??
Hi
I am using Oracle 9iAS (9.0.3) with OJMS as JMS Resource Provider. I could able to publish the messages and MDB's will be able to subscribes the messages.
How to subscribe the above message from External Java Client.
Can anybody will provide some sample code.
Thanks in Advance
MadhuThe problem here is how to register JMS destination (topic or queue) in JNDI and then to obtain the initial context where they can be looked up. Then the business is the same for an External Java Client as the code that runs in JSP.
To do it, you may see the code examples in
http://www.oracle.com/technology/sample_code/tech/java/jms/index.html
The second example, "JMS1.1 Domain Unification Sample" which is for 10g, does work for me. I did not try the first example, "JMS Sample Application", which is for oc4j 9.0.2 or higher. -
javax.servlet.jsp.JspException: Cannot find message resources under key org.apache.struts.action.MESSAGE
I already have in web.xml
application = ApplicationResources
I already checked that all the entries exists in the ApplicationResources.properties
as a parameter for action servlet, but still getting this message.
OliverI posit that it is not irrelevant, but rather crucial. The OP is not using the html <form> tag, but rather the Struts <html:form> tag which converts the action= attribute to the appropriate query-string equivalent. I give more detail here:
web.xml maps all *.do urls through the Struts servlet
struts-config defines an <action> with name='/foo'
author's jsp file uses Struts custom <html:form> tag with attribute action='foo'
this action= value MUST MATCH a struts-config action name value (sans *.do ending)
this design relieves the jsp author of having to know the web.xml servlet-mapping details
dlgrasse -
Hi Experts,
Scenario is for ISA-ECC.
We are recieving the message Id, Type, Num from ECC to the JAVA layer.
Is there any way that we could capture the Message Id, Num.
My intention is to check for the message number and display the custom message.
Custom message will be maintained in the resource key file.
There is something i encountered ui.getMessageString on the confirm.jsp.
Is their any possibility to change the message from the backend itself. Backend is ECC.
Experts,
Please help to resolve this issue.
Please let me know if more info is required.
Best regards,
Rohit SharmaThanks
-
Using EL variable in struts bean:message tag(not struts EL tag)
Is there any work around to use an EL variable inside struts bean:message tag as key:
I have like this:
<bean:message key="${bean.keyName}"/>
which is throwing error , I know this can be resolved by using struts-el tags but i cannot use them for specific reasons.
I dont want to use bean:define tag to define my 'bean' and then use like this:
<bean:message key="<%=bean.getKeyName%>"/> (this actually works, but i want to use EL variable)
Is there any work around to use EL variable and make the message display on the jsp.
i tried multiple ways like scriplets and jsp:useBean but nothing worked, Please let me know..
Thanks in advanceIm pretty sure that EL does not work in the normal struts tag unless its struts-el tag.Have you tried it?
As I said, in a properly configured JSP2.0 container you can use EL expressions anywhere you could traditionally use a standard runtime expression <%= expr %>.
What server are you using? What JSP version?
The Struts-el tags were written so that you could use EL with struts in JSP1.2 containers.
The c_rt tags were written so you could use runtime expressions with JSTL tags in JSP1.2 containers. Their use was discouraged even then. Now I consider their use absolutely unnecessary.
Please read this thread: http://forum.java.sun.com/thread.jspa?threadID=629437&tstart=0
Cheers,
evnafets
Maybe you are looking for
-
Please help. I have been using itunes with my ipod nano for years. Several months ago I did a requested upgrade and have not been able to open itunes since. I get an error message that says that itunes was not installed correctly. Error 7 (Windows er
-
My library (which includes items from CDs and items purchased from itunes) is on my old PC. I have a new PC and want to transfer the library. I can't see how to do this. I've turned Home Sharing on for both computers, but the Share doesn't show up
-
POSIX Performance Pack Error!
What's this means: Fri Mar 16 13:00:36 CST 2001:<I> <Posix Performance Pack> System has file descriptor limits of - soft: '1024', hard: '1024' Fri Mar 16 13:00:36 CST 2001:<I> <Posix Performance Pack> Using effective file descriptor limit of: '1024'
-
How can I get the firefox scrollbar on the right hand side of my screen to stay?
The scrollbar appears, but it goes away with this version. I would like to have it permanently stay.
-
I am an Sap hr consultant and i am looking to expand my skills and become ish consultant. Can anyone please let me know how to go about it...