|
楼主 |
发表于 2017-7-12 11:14:02
|
显示全部楼层
本帖最后由 ufo1982ufo 于 2017-7-12 11:16 编辑
参考了你给的链接,修改java文件如下:
- package mfxxl;
- import java.io.IOException;
- import java.net.InetAddress;
- import java.net.UnknownHostException;
- import javax.servlet.http.HttpServletRequest;
- import org.codehaus.jackson.map.JsonMappingException;
- import me.chanjar.weixin.common.exception.WxErrorException;
- import com.alibaba.fastjson.JSONException;
- import com.alibaba.fastjson.JSONObject;
- import com.justep.baas.action.ActionContext;
- public class GetIPAddress {
- public static JSONObject getIpAddress(JSONObject params, ActionContext context)throws JSONException, JsonMappingException, IOException, WxErrorException{
- HttpServletRequest request = (HttpServletRequest)context.get(ActionContext.REQUEST);
- String ipAddress = request.getHeader("x-forwarded-for");
- if(ipAddress == null || ipAddress.length() == 0 || "unknown".equalsIgnoreCase(ipAddress)){
- ipAddress = request.getHeader("Proxy-Client-IP");
- }
- if (ipAddress == null || ipAddress.length() == 0 || "unknown".equalsIgnoreCase(ipAddress)){
- ipAddress = request.getHeader("WL-Proxy-Client-IP");
- }
- if (ipAddress == null || ipAddress.length() == 0 || "unknown".equalsIgnoreCase(ipAddress)){
- ipAddress = request.getRemoteAddr();
-
- if (ipAddress.equals("127.0.0.1") || ipAddress.equals("0:0:0:0:0:0:0:1")){
- InetAddress inetAddress = null;
- try {
- inetAddress = InetAddress.getLocalHost();
- } catch (UnknownHostException e){
- e.printStackTrace();
- }
- ipAddress = inetAddress.getHostAddress();
- }
- }
- if (null != ipAddress && ipAddress.length() > 15){
- if(ipAddress.indexOf(",") > 0){
- ipAddress = ipAddress.substring(0, ipAddress.indexOf(","));
- }
- }
- JSONObject map = new JSONObject();
- map.put("ip", ipAddress);
- return map;
- }
- }
复制代码 在w文件中调用:
- Model.prototype.getIP = function(event){
- // debugger;
- var self = this;
- Baas.sendRequest({
- "url" : "/mfxxl/mfxxlgetip",
- "action" : "getip",
- "async" : false,
- "params" : {},
- "success" : function(data) {
- var ip = data.ip;
- self.mIP = ip;
- }
- });
- };
复制代码 这样可以获取到ip地址了,模型编译也没有出错,就是编译完后报错如下:
- 七月 12, 2017 11:11:15 上午 org.apache.catalina.core.StandardContext reload
- 信息: Reloading Context with name [/baas] has started
- 七月 12, 2017 11:11:15 上午 org.apache.catalina.loader.WebappClassLoader validateJarFile
- 信息: validateJarFile(E:\Wex5.3.6.3\apache-tomcat\webapps\..\..\runtime\BaasServer\WEB-INF\lib\servlet-api.jar) - jar not loaded. See Servlet Spec 2.3, section 9.7.2. Offending class: javax/servlet/Servlet.class
- 七月 12, 2017 11:11:35 上午 org.apache.catalina.core.StandardContext reload
- 信息: Reloading Context with name [/baas] has started
- 七月 12, 2017 11:11:35 上午 org.apache.catalina.loader.WebappClassLoader validateJarFile
- 信息: validateJarFile(E:\Wex5.3.6.3\apache-tomcat\webapps\..\..\runtime\BaasServer\WEB-INF\lib\servlet-api.jar) - jar not loaded. See Servlet Spec 2.3, section 9.7.2. Offending class: javax/servlet/Servlet.class
复制代码 这个是什么问题?
|
|