eclipse stops responding while running a .jsp file - eclipse

i have created a basic dynamic web project in eclipse.
my jsp file contains following code
<html>
<head>
<title>Insert title here</title>
</head>
<body>
this is the sum of 5 and 3 <%com.testing.SumOfNumbers.addTwoNumbers(3,5); %>
</body>
</html>
and in package "com.testing" i have created SumOfNumbers class with addTwoNumbers method.
package com.testing;
public class SumOfNumbers {
public static int addTwoNumbers(int a,int b)
{
return a+b;
}
}
i have downloaded tomcat v10.0 server.
I tried several times but same result. I don't know where the problem is ,is it in tomcat server or eclipse bug?
thanks in advance.

It's unlikely to be your code, although you're using a scriptlet instead of an expression, so the sum won't be in the output like you seem to expect.
https://wiki.eclipse.org/How_to_report_a_deadlock includes directions on how to get a stack dump to see what's going on.

Related

I am not able to run my apache wicket sample program

I am very new to java wicket. I don't understand how to run this code. My wicket program follows the structure below. My problem is that I am not able to run this. I am getting a 404 error.
This is my wicket code to get a hello world message.
HelloWorld.html:
<html xmlns:wicket>
<title>Hello World</title>
</head>
<body>
<span wicket:id="message" id="message">Message goes here</span>
</body>
</html>
</html>
HelloWorld.java:
package com.sensiple.wicket;
import org.apache.wicket.markup.html.WebPage;
import org.apache.wicket.markup.html.basic.Label;
public class HelloWorld extends WebPage {
public HelloWorld() {
add(new Label("message", "Hello World!"));
}
}
This class is returning hello world which is to be printed in HelloWorld.html
HelloWorldApplication.java:
package com.sensiple.wicket;
import org.apache.wicket.protocol.http.WebApplication;
public class HelloWorldApplication extends WebApplication {
//what is the need of this constructor, need of this class in this program
public HelloWorldApplication() {
}
I need to know what is the use of getHomePage-method too, as I am not getting what is the use of one more class here which returns return type as HelloWorld. Hardly I am not able to run this code. I went through many resources which didn't help.
public Class<HelloWorld> getHomePage() {
System.out.println("initialized!!!!");
return HelloWorld.class;
}
}
To start answering your many questions:
Your program is most likely returning a 404 due to the malformed HTML in your HelloWord.html. Wicket required valis XHTML to work with.
The original signature of getHomePage() is public abstract Class<? extends Page> getHomePage(). You can implement it as you did as it fullfills the contract. The method returns the class that is used to render the homepage of your web application. That's the page that is shown at the base-url of your application without any mountpoints or parameters.
You don't need the default constructor to your WebApplication but you can implement one to do some of the initialisations needed for your application. It's run once at the start of your application (or in most cases your container).
Try using this html:
<!DOCTYPE html>
<html xmlns:wicket="http://wicket.apache.org">
<head>
<title>Hello World</title>
</head>
<body>
<span wicket:id="message"></span>
</body>
</html>
When your application is running, just call http://localhost:8080 (unless you changed the port) and wicket should redirect you to your HelloWorld page

processing code shows nothing on the browser. don't know why

Does anybody know what's wrong with this code? It shows nothing in the browser.
My intention is to draw two eyes based on the mouse location. So I define an Eye class and then call its draw method with variable mouseX and mouseY.
However, it shows nothing on the browser.
Also, I wonder how to detect the size of the browser because screen.width and screen.height don't seem to work within a browser.
<!DOCTYPE html>
<html>
<head>
<script type="text/javascript" src="processing.js"></script>
<script type="text/processing" data-processing-target="mycanvas">
void setup(){
size(400,400);
smooth();
background(225);
}
if (mousePressed){
Face.draw(mouseX,mouseY);}
class Face{
float x,y,a;
Face(float ax,float ay){
x=ax;
y=ay;
a=random(1,5);}
void draw{
noFill();
stroke(0);
//eye1
ellipse(x+2.2*a,y-a,a/2,a/2);
//eyelashes1
arc(x+2.2*a,y-.5*a,1.2*a,1.2*a,PI,2*PI);
//eyebrows1
arc(x+3*a,y-.3,2*a,2*a,5/4*PI,9/4*PI);
//eye2
ellipse(x-2.2*a,y-a,a/2,a/2);
//eyelashes2
arc(x-2.2*a,y-.5*a,1.2*a,1.2*a,PI,2*PI);
//eyebrows2
arc(x-3*a,y-.3,2*a,2*a,5/4*PI,9/4*PI);
}
}
</script>
</head>
<body></body>
<canvas id="mycanvas"></canvas>
</html>
I'm a beginner, so I don't know if my problem is stupid or not.
But any hint is welcomed:)
Btw how to add color to the code on stackoverflow?
There are a some problems with your script.
Related with the html page:
You have to declare the encoding of the document in the header section: <meta charset="utf-8">
The canvas element should be included inside the html body.
Related with the processing code:
The processing script needs at least one setup() function and one draw() function. You defined a draw() method in your Face class, but not the main draw() function (by the way, you missed the brackets in your draw() method).
The mousePressed functionality should be included inside the main draw() method.
You need at least to declare one instance of your Face class (inside the setup() function). For example: Face myFace = new Face(10, 10);.
And probably more syntax errors inside your draw() method...
My recommendations:
Start with something simpler: The more lines you write from scratch, the harder to debug. Try to draw first just an ellipse and incrementally add more things to your code.
Keep your processing script in a separate file. It's cleaner and you can debug it using the processing editor or the processing online sketch:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Testing testing</title>
<script type="text/javascript" src="processing.js"></script>
</head>
<body>
<canvas id="my-sketch" data-processing-sources="my-sketch.pde"></canvas>
</body>
</html>
Check this tutorial to get some ideas about objects and classes in processing.
The syntax in processing is very similar to java, and there're a lot more resources for understanding the basics of OOP for that language. Just google for it.
For syntax highlightning, look here.

Kentico CMS: Add a class attribute to the html tag in a Kentico Masterpage

How do you edit the HTML tag in a Kentico CMS Masterpage, i.e. to add a class attribute?
Currently I have this:
But I want:
<!DOCTYPE html>
<html class="myClass">
<head>
<title>
From the screenshot you can see that the HTML tag is not editable.
Is there a way to edit the html tag or tell Kentico to write a class attribute to the html tag?
I have found one solution:
I manually added a class attribute to the HTML tag in this file:-
<solution>/CMSPages/PortalTemplate.aspx
You can also use the "Head HTML" web part on your page template(s).
It is quite disappointing that Kentico still does not support this out of the box. A request to be able to modify the <html> tag directly from code has been filed: http://ideas.kentico.com/forums/239189-kentico-product-ideas/suggestions/5947264-ability-to-modify-page-head-section-and-html-tag
In the meantime use the following solutions:
Portal Engine
I solved this the following way, based on Dave Haigh suggestion. In the file /CMSPages/PortalTemplate.aspx change the following line:
<html xmlns="http://www.w3.org/1999/xhtml" <%=XmlNamespace%>
lang="<%=CMSContext.PreferredCultureCode%>">
ASPX Engine
In your master page, add the following snippet to your code behind file:
<script runat="server">
protected void Page_Load(object sender, EventArgs e)
{
if (CurrentDocument != null)
{
CMS.UIControls.ContentPage page= this.Page as CMS.UIControls.ContentPage;
if (page != null)
{
string lang= CMS.Localization.LocalizationContext.CurrentCulture.CultureCode;
page.XmlNamespace += " lang=\"" + lang + "\"";
}
}
}
</script>
Source: http://devnet.kentico.com/questions/kentico-9-how-to-define-language-in-html

Testing Wicket panels with constructor arguments

I got a page with several panels that takes several parameters in their constructors.
One of them being a menu that takes a list for the different buttons in the menu.
I've tried to test it as components but get a null pointer exception. Using a dummy page and creating the panel on the dummy page works.
I'm not entirely happy with this approach since it introduces a lot of new code in my tests and more possibilities for errors.
Is there a better way of testing panels that takes arguments in their constructor?
Sure thing:
The code that gives an null pointer error:
public void testVisitPanel(){
VisitPanel v = new VisitPanel("visitPanel");
tester.startComponent(v);
tester.assertContains("DATE");
}
The panel
public VisitPanel(String id) {
super(id);
add( new Label("visitDate", "DATE"));
add( new Label("visitStage", "VISIT SIGNED"));
}
And the html
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html
xmlns="http://www.w3.org/1999/xhtml"
xmlns:wicket="http://wicket.sourceforge.net/"
xml:lang="en"
lang="en">
<wicket:head>
</wicket:head>
<body>
<wicket:panel>
<span wicket:id="visitDate">VISIT DATE</span>
<span wicket:id="visitStage">STAGE</span>
</wicket:panel>
</body>
</html>
If you're using Wicket 1.4, you probably want wicketTester.startPanel.
What I do is create an implementation of ITestPanelSource in the test, doing something like:
private class TestPanelSource implements ITestPanelSource {
private static final long serialVersionUID = 1L;
public Panel getTestPanel(String panelId) {
return new MyPanel(panelId, myArg1, myArg2);
}
}
with the myArgN being fields in the test class (frequently mocks) that suit the constructor, and then call it in the test or in a setUp method with
wicketTester.startPanel(new TestPanelSource());
This is basically doing some of the DummyPage work for you, so it may not be that far from what you're doing now, but might at least save on implementation of dummy pages for test infrastructure.
In Wicket 1.5, this is deprecated in favor the component testing that you referenced in the question. That should also work, so it might be worthwhile to post some actual code that is giving you trouble with that technique.

How to integrate CKFinder with CKEditor?

How do you integrate CKFinder with the new CKEditor.
It is very underdocumented on the website, and i am literally getting nowhere.
A step by step guide would be greatly appreciate as, as far as i am aware.. this is the only free/good image upload solution for a wysiwyg editor that is any good. Can someone confirm?
Thanks
You can find a tutorial on integrating CKFinder with CKEditor here:
http://www.webshaolin.com/index.php?page=article&articleid=40
Try doing following steps.
1. Download CKEditor and CKFinder. Integrated code may be available on http://dwij.co.in/ckeditor-ckfinder-integration-using-php/
2. Put extracted code of both in one folder inside xampp as below.
3. Create index file (index.html) which will be containing the editor as below code.
<html>
<head>
<script type="text/javascript" src="ckeditor/ckeditor.js"></script>
<script type="text/javascript" src="ckfinder/ckfinder.js"></script>
</head>
<body>
<h1>CKEditor CKFinder Integration using PHP</h1>
<textarea id="editor1" name="editor1" rows="10" cols="80"></textarea>
<script type="text/javascript">
var editor = CKEDITOR.replace( 'editor1', {
filebrowserBrowseUrl : 'ckfinder/ckfinder.html',
filebrowserImageBrowseUrl : 'ckfinder/ckfinder.html?type=Images',
filebrowserFlashBrowseUrl : 'ckfinder/ckfinder.html?type=Flash',
filebrowserUploadUrl : 'ckfinder/core/connector/php/connector.php?command=QuickUpload&type=Files',
filebrowserImageUploadUrl : 'ckfinder/core/connector/php/connector.php?command=QuickUpload&type=Images',
filebrowserFlashUploadUrl : 'ckfinder/core/connector/php/connector.php?command=QuickUpload&type=Flash'
});
CKFinder.setupCKEditor( editor, '../' );
</script>
</body>
</html>
so your folder structure will be something like this:
htdocs
|_integrated
|_ckeditor
| |_config.js
| |_...
|_ckfinder
| |_config.php
| |_...
|_uploads
|_index.html
Now open file config.php inside ckfinder & make following changes:
function CheckAuthentication() {
// WARNING : DO NOT simply return "true". By doing so, you are allowing
// "anyone" to upload and list the files in your server. You must implement
// some kind of session validation here. Even something very simple as...
// return isset($_SESSION['IsAuthorized']) && $_SESSION['IsAuthorized'];
return true; // not good option though; go for sessions
}
$baseUrl = 'http://localhost/integrated/uploads/';
$enabled = true;
$config['SecureImageUploads'] = false;
$config['ChmodFolders'] = 0777 ;
Now open url http://localhost/integrated/ and try uploading image.
Check the documentation site for your server language: http://docs.cksource.com/CKFinder_2.x
For example this part of the PHP docs: http://docs.cksource.com/CKFinder_2.x/Developers_Guide/PHP/CKEditor_Integration
And btw, CKFinder is not free, you must get a license in order to use it.
First you must have a textbox to convert to CKEditor:
<textarea id="newTextArea">Some text</textarea>
Then all you need is some javascript code for the conversion of this texteditor to a CKEditor instance and the integration of this editor with CKFinder.
<script type="text/javascript">
var newCKEdit = CKEDITOR.replace('newTextArea');
CKFinder.setupCKEditor(newCKEdit, '/ckfinder/');
</script>
The second parameter of the setupCKEditor function must be the folder in your website where you uploaded ckfinder.
http://docs.cksource.com/CKFinder_2.x/Developers_Guide/PHP/CKEditor_Integration