Issue regarding JSP Forward - java

In my code I am trying to forward my request by using below line
<jsp:forward page = "<%=request.getContextPath()%>/Welcome.do"/>
However its giving error below
org.apache.jasper.JasperException: /obajsp/OBAHeader.jsp(3,27) JBWEB004214: Error unquoting attribute value
Please someone help me to understand what is issue in my written code?
EDIT:
this was currently working in production without any issue and giving issue in my local IDE

Have you tried using the expression language, rather than a scriptlet?
<jsp:forward page = "${pageContext.request.contextPath}/Welcome.do"/>

<jsp:forward page = "${pageContext.request.contextPath}/Welcome.do"/>
you dont need inline java to get the context path. expressionlanguage is much more comfortable.

Related

Refeshring JSP page in Javascript

I am trying to refresh the JSP page after certain operations, I am using DWR to be able to use my classes in Javascripts in the JSP files so I have this code:
function removeDN(numplanindex){
DBOps.removeDN(numplanindex);
relaod(true);
}
the above code will break the removeDN() and it would not refresh the page, I have also tried window.location.reload(true) and document.location.reload(true).
I am not sure about the difference as I barely know any Javascript but according to everything on google this should work. I am wondering if anybody know what is wrong with what I am doing wrong.
Thanks
It should be reload(true) instead of relaod(true)
Also see http://www.w3schools.com/jsref/met_loc_reload.asp

Dynamic Extjs DateFields in the dynamic form

I am very much thankful to this stackoverflow,as i am getting required help very quickly here.
I am facing a problem in ExtJs.(with java spring backend combination). I am having a jsp file like this.
<c:when test="${eformDetails.controlType=='date'}">
<span id="eform_date_${eformDetails.id}"></span>
</c:when>
And in the js file i am trying to create date objects like this.But not working :-(
$.each('span[id^=["eform_date_"]',function(){new Ext.form.DateField({renderTo:this.id,name: 'form_0',id :'date_'+this.id,width: 140});});
My Requirement is if the eformDetails.controlType is date then i have to display a date field there.
Could please help me in this.
I am very much thankful to you guys..
Thanks in advance
-Sathya
The selector you're looking for is probably:
$.each('span[id^=eform_date_]', function() { /* DateField */ });
The unmatched bracket is a syntax error. You can test it in your browser's console to make sure you're getting it right.

Why is Eclipse/JSP parsing my JavaScript?

I have a JSP page which doesn't actually have any server tags in it so its basically an HTML page. But, my work is in love with JSP so I set it as a .jsp file. Anyhow, Tomcat is under the belief that my JavaScript is in fact Java code and tries to parse it. I get a nice big error on the screen saying its not a real function, etc. Could anyone tell me why its doing this? Code below...
...
<script>
$(function() {
$.dragAndDrop({
dom: {
fileList: '#fileList tbody',
contextMenu: '#fileContextMenu',
dropzone: '#dropzone'
},
templates: {
file: '<tr><td>${fileName}</td><td>${$.dragAndDrop.getDate()}</td><td>${$.dragAndDrop.parseSize(size)}</td></tr>'
}
});
});
</script>
...
The error:
org.apache.jasper.JasperException: /index.jsp(22,42) The function getDate must be used with a prefix when a default namespace is not specified
org.apache.jasper.compiler.DefaultErrorHandler.jspError(DefaultErrorHandler.java:40)
org.apache.jasper.compiler.ErrorDispatcher.dispatch(ErrorDispatcher.java:407)
org.apache.jasper.compiler.ErrorDispatcher.jspError(ErrorDispatcher.java:148)
${} marks expressions for evaluating via JSP. As you say you don't use any JSP, you can disable the expressions language by adding
<%# page isELIgnored="true" %>
to your page.
It is likely the ${ notation
Try replacing this code ${$
with something like this $' + '{$
or $<%='{'%>$
I don't know if there is a proper way to escape that,, but what I just gave you should work.
See Google for more information. The top result looks good but I could not find how to do a proper escape: http://www.google.com/search?q=jsp+dollar+sign

JSP renders weird HTML

I'm getting a very strange behaviour in one of my JSP pages. It looks like it doesn't render the complete HTML. It looks like this:
<html>
...
<table>
...
</table>
<div id=
So the last line is exactly what you get when the page is rendered. Furthermore, when you do a view source you get exactly the same. This page doesn't have any fancy logic ... there are no javascript erros, no missing closing tags, etc ...
Is there any sort of page limit for a jsp page?
A bit more background: This page works just fine in a WIN2K server running Tomcat 5.5. I'm upgrading this app to run under a server with WIN2008 + Tomcat 6.0. That's where I get the error ...
Any help is appreciated.
Is there any sort of page limit for a jsp page?
AFAIK, no.
I think that the most likely cause is that your JSP is throwing an exception. Check the Tomcat logs, and look at the JSP at the point after the last HTML that was output.
EDIT
#Adam Crume says: "The exception may be thrown at a point further down from where the output stops, due to buffering."
True. As a temporary hack to get around this, you could surround the JSP's content with a try / finally, and flush the output stream in the finally block.
Is there any sort of page limit for a jsp page?
Yes, there is. It's about 64KB. JSP's are basically compiled into a large try statement. In Java, there's a 64KB limit for try statement. But if you exceed this, it would have prouced a different exception.
This problem at least indicates that you're using scriptlets in the JSP. This is a bad practice. Whenever an exception occurs halfway a JSP page, you'll get a blank or halfbaked page without information about the problem. Don't execute business stuff in JSP, but in a preprocessing Servlet.

Cannot redirect with the response.sendRedirect

I googled and googled for hours on how to make a redirect in jsp or servlets.
However when i try to apply it, it doesn't work.
Code that i have inside jsp page:
<%
String articleId = request.getParameter("article_id").toString();
if(!articleId.matches("^[0-9]+$"))
{
response.sendRedirect("index.jsp");
}
%>
I know from debugging that regexp works and if any time, articleId is not number, the if goes inside, however when it reaches response.sendRedirect it doesn't actually makes redirect.
Do I miss something very fundamental in this case ?
Thanks in advance.
You should return after redirecting:
response.sendRedirect("index.jsp");
return;
Is there content before this scriptlet? If so, the redirect wouldn't work.
Also, the common practice is to have such logic inside a servlet or other class serving as controller, and leaving the JSP to only handle the rendering of the HTML. It may also solve your problem. For example, see here

Categories

Resources