PDA

View Full Version : Can't get servlet to be invoked by extjs javascript code



extjsnb
1 Aug 2011, 1:23 PM
Hello,

I have a webapp using java, extjs deployed in Tomcat. I am trying to call a servlet from a js. I can call the servlet directly and it comes up. But extjs cannot. Please help!!

index.js:

/*

This file is part of Ext JS 4

Copyright (c) 2011 Sencha Inc

Contact: http://www.sencha.com/contact

GNU General Public License Usage
This file may be used under the terms of the GNU General Public License version 3.0 as published by the Free Software Foundation and appearing in the file LICENSE included in the packaging of this file. Please review the following information to ensure the GNU General Public License version 3.0 requirements will be met: http://www.gnu.org/copyleft/gpl.html.

If you are unsure which license is appropriate for your use, please contact the sales department at http://www.sencha.com/contact.

*/
Ext.require([
'Ext.form.*',
'Ext.layout.container.Absolute',
'Ext.window.Window'
]);

Ext.onReady(function() {
var form = Ext.create('Ext.form.Panel', {
layout: 'absolute',
url: 'test3',
defaultType: 'textfield',
border: false,

items: [{
fieldLabel: 'Send To',
fieldWidth: 60,
msgTarget: 'side',
allowBlank: false,
x: 5,
y: 5,
name: 'to',
anchor: '-5' // anchor width by percentage
}, {
fieldLabel: 'Subject',
fieldWidth: 60,
x: 5,
y: 35,
name: 'subject',
anchor: '-5' // anchor width by percentage
}, {
x:5,
y: 65,
xtype: 'textarea',
style: 'margin:0',
hideLabel: true,
name: 'msg',
anchor: '-5 -5' // anchor width and height
}]
});

var win = Ext.create('Ext.window.Window', {
title: 'Resize Me',
width: 500,
height: 300,
minWidth: 300,
minHeight: 200,
layout: 'fit',
plain:true,
items: form,


buttons: [{
text: 'Reset',
handler: function() {
this.up('form').getForm().reset();
}
}, {
text: 'Submit',
handler: function() {
Ext.MessageBox.alert('Submitted Values', 'Submitted Values');

this.up('form').getForm().submit();
}
}]


});

win.show();
});




web.xml

<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" id="WebApp_ID" version="3.0">
<servlet>
<servlet-name>Test</servlet-name>
<servlet-class>test.FileUploadTest</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>Test</servlet-name>
<url-pattern>/test3</url-pattern>
</servlet-mapping>
</web-app>


I can bring up the servlet with: http://localhost:8080/TestExtJs/test3


But in index.js (shown above), I have

url: 'test3',

and in the button handler for the submit button, I have:

this.up('form').getForm().submit();

Shouldn't this submit the form and call test3?

Please help...I must be overlooking something simple!

Thanks in advance.

extjsnb
8 Aug 2011, 6:02 AM
This has been solved. I simplified the code and it worked just as the examples showed.

viniciusmelo
13 Aug 2011, 5:04 PM
Do you get some response from that servlet?

I started another thread about something like this, in my case I'm trying to read the response in HTML not in JSON, which seems to be the standard ...