Apple Khoa

Ranch Hand
+ Follow
since Jul 27, 2011
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
In last 30 days
0
Forums and Threads

Recent posts by Apple Khoa

Dear all,

I have created the following webpage which I want to link to another webpage depending on the user's selected option.

My Webpage:


My HTML Code:
Within <head> </head>

Within <body> </body>


Problem Faced:
No matter what the user selects, the webpage always link to http://localhost:8080/Math/page2.html of the else statement.
How can I modify the code to have the if statement works correctly?


All help will be greatly appreciated.

Thanks in advance!

James E Baker wrote:I don't think there's anything in the code you posted causing any delays. It's pretty basic stuff... just random number generating and switch statements. The only part that I am not sure about is the "doc.add" statement but I doubt that would do it either.

You could always //comment out parts (or all) of the code and then test your servlet.



Thanks, James E Baker. I adopted your advice and //comment out parts of the code to find out what's going wrong. Indeed, it helps!
13 years ago
Dear all,

I have written the following code in my Servlet, but the time taken by the web page (with localhost) to generate the output takes more than 4 minutes. I am not sure if it is due to my code, hence I am posting my code here to check it out.



If my code is the root of the long loading time, could anyone kindly advise me how I could improve the code?
(By the way, base3LHS and base3RHS cannot be grouped together though they are identical because the terms are supposed to represent different parameters in the doc.add statement)

Otherwise, I would appreciate if anyone could suggest what could be the possible reasons behind the long loading time.

Thanks in advance.
13 years ago
Dear all,

Is it possible to display fractions as how human will normally write [e.g. superscript(3) / subscript(4)] with Java, rather than displaying it as "3/4"?

I am aware that Latex can display fractions, but from what I can understand, it cannot be embed into Java code to give a .java file. Kindly correct me if I am wrong.

All advices will be greatly appreciated.

Thanks in advance.
13 years ago

Ulf Dittmer wrote:You can't have a method inside of a method.

I'm not quite sure what you're trying to do, but I very much doubt that it's going to work. The Servlet API has no provisions for a "paint" method.



I am trying to draw Quadratic curves with my Servlet which will then output the curve in pdf format. I thought I can achieve that using Graphics2D in the java.awt.Graphics2D. So, can I say that Graphics2D is not supported in servlet?
Hi all,

I am trying to plot a quadratic curve in a servlet which will display the output as a pdf file. I am not sure if Graphics2D in java.awt.Graphics2D can be used in servlet, so i gave it a try. I face some problems as described below:

My servlet code:


Error shown by Eclipse:

public void paint(Graphics g)


Suggestion by Eclipse: "Void is an invalid type for the variable paint" (This wasn't a problem if it is a normal Java file, not a servlet)

Error shown by Eclipse:

doc.add(new Paragraph(quadcurve));


Suggestions by Eclipse:
1. "Remove argument to match Paragraph();" > Doing so will remove the quadcurve
2. "Change type of quadcurve to float" > But quadcurve is not a float in the first place.

Any help to resolve this issue will be greatly appreciated.

Thanks in advance.
Hi Jesper De Jong,

Thank you so much for your clear explanation. This is my first time attempting graphs/charts with Java, so pardon me if I ask a lot of questions.

From what I understand in your explanation, the libraries and BufferedImage (with getGraphics) draw graphics that are 'permanent' in the sense that the graphics cannot change according to the Inequalities which will vary (e.g, sometimes X>2, sometimes x<25 etc). Kindly correct me if I am wrong.

My program will set questions and solve the inequalities, and then display it on the number line.
E.g
x - 3 > 5
x > 8
(display x >8 on number line)
13 years ago
Hi Jesper De Jong,

May I know what do you mean by "do the drawing yourself"?

Actually, I intend to write the mathematical logic for the topic Inequalities, and the inequality should be shown on the number line as the final answer. Hence, the 'chart' should change according to the inequality. All these will be included in servlets, which will output pdf file.

In my case, is BufferedImage and getGraphics still applicable?
13 years ago

Maneesh Godbole wrote:Check out the API for the Graphics class. You will find methods to draw lines and text (hint)
1) Subclass a container like JPanel



Hi Maneesh Godbole,

Thanks for your prompt reply.

I am aware that Java Graphics class has a drawLine function which allows users to draw a straight line. But from what I understand, it doesn't show the axis values even if I draw the x-axis as a straight line.

You mentioned about JPanel. Can that be implemented into servlets? My ultimate objective is to insert the code into my servlet which will then generate the inequality number line as a pdf file for output.

I learnt from the Internet about JGraphT. May I ask if that is applicable for my case (since JGraphT produces postscript, can that be implemented into servlets?)

Thank you very much for your kind help.
13 years ago
Hi all,

Does anyone knows what Java tools can I use to create the following Inequality Number Line? I do not want Java Applets.



All advices will be greatly appreciated.

Thanks in advance!
13 years ago

Bear Bibeault wrote:You learned wrongly.

You use the mapping. Forget about the silly "/servlets" string.



What's wrong with my mapping?


along with my ControlServlet code:


The html page, servlets are all in the same folder (Apache tomcat > webapps > helloservlet)

HTML in Apache tomcat > webapps > helloservlet
Servlets classes in Apache tomcat > webapps > helloservlet > WEB-INF > classes > simuleqn
13 years ago

Bear Bibeault wrote:I do not see the string "/servlet" in your mappings. Why is it in your URL if it's not in your mapping?



I learnt from websites that I can invoke servlet from browser using http://machine-name:port/servlet/servlet-name. Inserting "/servlet" in my mappings doesn't help too, producing the same error.
13 years ago

Bear Bibeault wrote:Not surprising as that doesn't match any of your servlet mappings. You can't just make up URLs. You have to use the actual mappings.



Actual mappings? Is it like this (my modified web.xml):



Error displayed when I invoke the servlets using http://localhost:8080/servlet/EasyQnServlet:


HTTP Status 404 - /servlet/EasyQnServlet
--------------------------------------------------------------------------------
type Status report
message /servlet/EasyQnServlet
description The requested resource (/servlet/EasyQnServlet) is not available.

13 years ago

Bear Bibeault wrote:What happened when you tried to hit the servlets directly using the browser?



When I tried to invoke the ControlServlet with http://localhost:8080/servlet/ControlServlet, Error 404 appears with no details shown.
The same thing happened when I invoked EasyQnServlet with http://localhost:8080/servlet/EasyQnServlet.

But is it supposed to show something since my servlets has to receive users inputs (get.Parameter) before it can output anything?

13 years ago

Bear Bibeault wrote:What happened when you tried to hit the servlets directly using the browser?



Everything was working fine when I call the EasyQnServlet directly from my webpage without the ControlServlet 'in between'. However, Error 404 (no details shown) surfaces when I add and call ControlServlet, which has the code attached above. I have no idea if it is the coding in the ControlServlet, or the mapping in the web.xml that is wrong.
13 years ago