Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp

Daniil Sosonkin

Ranch Hand
+ Follow
since Jan 15, 2004
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Daniil Sosonkin

Its a plain JSP code. I don't know what page controller is, to be honest. So far I'm concentrating on the exception, maybe should look into something else. Let me give you a snippet:

<c:set var="news" value="${o:getNews(quote, param.start, 20)}" scope="request" />

Where getNews is defined as:

<function>
<name>getNews</name>
<function-class>com.Quotes</function-class>
<function-signature>java.util.List getNews(com.Quote,int,int)</function-signature>
</function>

The function already takes care of all illegal values for all its parameters. Anything that I'm missing?
11 years ago
JSP
Right now the logic is to throw an exception when a string cannot be converted to a target number type. My logic is to silently ignore the exception and return some default value such as 0 (zero). Maybe also log an error as a warning.
11 years ago
JSP

Bear Bibeault wrote:Validate the values in the JSPs page controller prior to forwarding to the JSP.




The exception tree is as follows:

javax.servlet.jsp.el.ELException: An exception occured trying to convert String "4555555555555" to type "int"
org.apache.commons.el.Logger.logError(Logger.java:481)
org.apache.commons.el.Logger.logError(Logger.java:498)
org.apache.commons.el.Logger.logError(Logger.java:566)
org.apache.commons.el.Coercions.coerceToPrimitiveNumber(Coercions.java:440)
org.apache.commons.el.Coercions.coerce(Coercions.java:332)
org.apache.commons.el.FunctionInvocation.evaluate(FunctionInvocation.java:167)
org.apache.commons.el.ExpressionEvaluatorImpl.evaluate(ExpressionEvaluatorImpl.java:263)
org.apache.commons.el.ExpressionEvaluatorImpl.evaluate(ExpressionEvaluatorImpl.java:190)
org.apache.jasper.runtime.PageContextImpl.proprietaryEvaluate(PageContextImpl.java:917)
org.apache.jsp.secure.research.news_005fajax_jsp._jspx_meth_c_set_0(news_005fajax_jsp.java:143)
org.apache.jsp.secure.research.news_005fajax_jsp._jspService(news_005fajax_jsp.java:112)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:97)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:334)
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:802)
net.sourceforge.stripes.controller.StripesFilter.doFilter(StripesFilter.java:246)
...SecurityFilter.doFilter(SecurityFilter.java:98)


My thinking is to change that Coercions.java file. Haven't checked whether source is public or not yet. Maybe a better way?
11 years ago
JSP

Bauke Scholtz wrote:

which the clients don't like


So your clients are expected to act like malicious users?
I wouldn't worry about it after all. They are asking for the error themselves and they will get error too.

At any way, a solution is hard to give as it is not clear how you implemented this logic. There are many ways to achieve this.



Well, the idea is I'm able to handle the errors gracefully. In this particular incident, instead of displaying a general site error I would display the very first page. In another instance, such as an order entry and keyboard got stuck on quantity or a fat finger, I would display quantity has to be greater than zero.

If you have suggestions, please.
11 years ago
JSP
Hi folks,

A small question on whether it is possible to do or not. My application is being checked for bugs and such right now. One of the "issues" has to do with data conversions in JSP using EL. Lets say a page number is passed on to JSP page via URL: ?page=XXX. This page is then being converted into an integer value to be passed on to a bean. But lets say a "malicious" user plays with the URL and puts in ?page=abc444 or ?page=200000000000000000000000000. In both cases that causes an exception to be generated which the clients don't like. In a cases such as these, is it somehow possible to make EL simply convert bad number into a 0 (zero) and ignore any errors? I mean - I really don't care for the number that cannot be converted into an integer. My other solution is to rewrite the beans to accept Strings and do the checking myself, but I really would like not to pollute the code like that.

Any suggestions?

Thanks in advance
11 years ago
JSP
Hmm, lets see, NetBeans is built upon Ant which makes it rather complicated to use with projects already having Ant scripts. When trying to use NetBeans, I've been told (not exact words) - "There's already build.xml file. Unable to create project." Fantastic! This is the IDE of the future I would like to keep my build.xml and would like to have it simple so that I can understand what is in it. Also, I would like to have total freedom of creating my project's dir structure without IDE telling me how to do it.
IntelliJ has one of the best CVS integrations out there (in my opinion at least). It is very simple to checkout project. While you are editing a file, it will show you what you've changed as you work on your changes. Committing the files, updating the projects is more than easy. But I'm biased because when trying to work with Eclipse or NetBeans I've encountered many gurdles. Plus, being not very fluent with CVS, IntelliJ is a life-savor.
I'm not sure that one should look at amount of plugins as an evidence of better IDE. Yes, there are a lot of plugins for IntelliJ although not as much as for others. But to my opinion, IntelliJ is fine without any plugins and that is what makes it wonderful. Besides, why would you need more than one plugin - tetris - I love that thing! But anyway, I have only few plugs installed - tetris, regex, and simpleUML. Have I ever needed more? No, not really; and I'm doing development in all areas ranging from complex real-time servers and web apps to simple applets and text parses.

And so you know, yes, I've tried using Eclipse, and yes, I'll do my best not to use it ever again.
Wicket is very close to Tapestry. But unfortunately I can't get it run on Tomcat. It never finds an HTML template on me. No matter where I put it.
Ooops, I just realized that I confused Wicket with Echo! Wicket does look great... I'll have to take a closer look into it. Thanx!
Thanks everyone I actually got it figured out. Its my first step into frameworks in general (after years of dev in JSP/Servlets). Just takes time to get used to. Yeah, have to purchase that book - is it the only one? - just got to find time.

I've created a User object as soon as I began (seemed obvious) just didn't know where exactly to stick it or where should I check for it. Funny, I'd think that a framework would provide some build-in way of doing something so rudimentary.
Yes, they all have similar concept - you put an object into the session But I'm looking for Tapestry in particular because I've already chosen this framework. Wicket was also considered, but I giving designers more freedom w/ least feedback on my side.
Hello,

I'm looking to write quite a system in JSP/Servlets, but this time I'd like to use some kind of framework. When writing stuff using good old Java I end up writing part of Tapestry or JSF and such. After looking at frameworks available, I find Tapestry the most appealing (mainly because designers do not touch/see code). But the trouble for me is to get off the ground. All pages on the site will be password protected. So no matter where you go, you must be logged in. But I just can't find a good tutorial which will show me how to login/logout user (or even how to make a single logon). Everyone just keeps showing simple examples and benefits of the framework - please, can anyone give me a sample of how I can do login/logout w/ User object in memory? I'm all confused on where to start.

Many thanks!
Well, at this moment I feel absolutely stupid I've done as Wagner has suggested and basically wrote the same Quote structure as used in C++ into Java. Guess what, stupid stupid me, the result is now that everything seems to be fitting into memory:

Quote about: 112
Trade about: 32
Symbol about: 44
Array: 22,309,832 (array of 192326 Quote)

Now I'm writing a quick program to see how it handles w/ the data. But so far - stupid stupid stupid!
14 years ago
Thats rather simple. The overhead of describing data is a little bigger in Java. Take my Quote class. It contains classes Symbol, Level2, String, Regional and Trade. Then Level2 contains in itself L2Bid and L2Ask which in turn contain Symbol classes. From what I've read the overhead for each class instance can reach up to 12 bytes (for the life of me I can't remember where I've read except that it was somewhere on theserverside.com). Lets not forget that arrays in Java are just special Objects. But in C++, I'm using structs to contain the same data. Also, I'm not using any special Symbol class but just char[]. All in all it came out to less memory allocation. Unless, of course, (c) applies here. Also, I still didn't implement Level2 in C++ so I'm not sure how it will hold up. It seems there's a need to change the implementation - which will prompt me to rewrite Java code as well.
14 years ago