javascript - Java method call using dojo -
i have java class contains method, having business logic in it. need call java method directly jsp (except through servelet or struts action or scriplets) on button click. know can done using dwr (as per behavior), there possibilities call java methods directly using dojo framework?
i concern dojo instead of using dwr because in application i'm using dojo framework. app contains struts2 without calling struts action, using dojo (ajax calls) need call particular java method directly in dwr.
people have experience in using dojo please guide me on this.
note: please let me know if require code parts of app, think above description might fine enough understand motive.
thanks.
zulox,
what need set model-view-controller architecture web application. this, can invoke method in back-end code upon click has occured in front end.
with mvc, view provides user interface element of application. it'll render data model form suitable user interface.
the controller receives user input , makes calls model objects , view perform appropriate actions.
the model manages fundamental behaviors , data of application.
you jsp following:
<%@page contenttype="text/html" pageencoding="utf-8"%> <!doctype html> <html> <head> <meta http-equiv="content-type" content="text/html; charset=utf-8"> <title>jsp page</title> </head> <body> <form action="add" method="post"> value 1:<input type="text" name="val1" id="val1"/><br> value 2:<input type="text" name="val2" id="val2"/><br> <input type="submit" value="submit"/><br> </form> <%string sum=""; sum = (string)request.getattribute("val3"); %> <input type="text" value="<%=sum%>" /> </body> </html>
and java file in back-end following:
package controller; import java.io.ioexception; import java.io.printwriter; import javax.servlet.servletexception; import javax.servlet.http.httpservlet; import javax.servlet.http.httpservletrequest; import javax.servlet.http.httpservletresponse; public class add extends httpservlet { string val3; protected void processrequest(httpservletrequest request, httpservletresponse response) throws servletexception, ioexception { response.setcontenttype("text/html;charset=utf-8"); printwriter out = response.getwriter(); string val1=request.getparameter("val1"); string val2=request.getparameter("val2"); if(val1 != null && val2 != null) val3=""+(integer.parseint(val1)+integer.parseint(val2)); else val3=""; request.setattribute("val3",val3); request.getrequestdispatcher("index.jsp").forward(request, response); try { } { out.close(); } } @override protected void doget(httpservletrequest request, httpservletresponse response) throws servletexception, ioexception { processrequest(request, response); } @override protected void dopost(httpservletrequest request, httpservletresponse response) throws servletexception, ioexception { processrequest(request, response); } @override public string getservletinfo() { return "short description"; }// </editor-fold> }
you're going need web server/servlet container can host end files , serve jsp's. apache tomcat great 1 start learning on. here , here great tutorials tomcat started setting can serve pages.
please let me know if have questions!
Comments
Post a Comment