andysern
andysern
采纳率6.3%
2016-05-21 14:27

jsp javabean怎么没有办法用类定义的方法呢?

创建一个随机以IP地址,时间等命名的字符串,但是里面setIPTimeStmap的方法却一直报错,但是使用getIPTimeRand()却可以得到正确的结果(只是没有IP地址)。是什么原因呢?

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Random;

public class IPTimeStamp {

 private SimpleDateFormat sdf = null;
 private String ip = null;


 public IPTimeStamp(String ip) {
     super();

     this.ip = ip;
 }


 public IPTimeStamp() {
     super();
 }

 public void setIpTimeStamp(String ip){
     this.ip = ip;

 }
   public String getIPTimeRand(){
     StringBuffer buf = new StringBuffer();
     if(this.ip != null){
         String s[] = this.ip.split("\\.");//根据ip以点分割将IP中的数字提取
         for(int i = 0 ; i < s.length; i++){
             buf.append(this.addZero(s[i], 3));//不够三位数的补零
         }
     }
     buf.append(this.getTimeStamp());
     Random r = new Random();//再在结尾加上三个随机数
     for(int i = 0 ; i < 3 ; i++ ){
         buf.append(r.nextInt(10));
     }
     return buf.toString();
 }


    也就是说,已经正确引入了javabean,可以正确使用,但是就是不能SET IP。
  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享
  • 邀请回答

4条回答

  • lzj0327 lzj0327 5年前

    ip打出来看看,或者把项目清了重新发布呢,或者修改编码,这些都试试

    点赞 评论 复制链接分享
  • andysern andysern 5年前

    HTTP Status 500 - An exception occurred processing JSP page /img_updata/doUpload.jsp at line 56

    type Exception report

    message An exception occurred processing JSP page /img_updata/doUpload.jsp at line 56

    description The server encountered an internal error that prevented it from fulfilling this request.

    exception
    org.apache.jasper.JasperException: An exception occurred processing JSP page /img_updata/doUpload.jsp at line 56

    53: }
    54: out.println("文件来自于 ip:"+ip);
    55:

    56: getIpName.ip_set(ip);
    57: out.println(getIpName.getIPTimeRand());
    58:
    59: //out.println(getIpAddr(request));

    Stacktrace:
    org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:574)
    org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:461)
    org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:396)
    org.apache.jasper.servlet.JspServlet.service(JspServlet.java:340)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
    org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)

    点赞 评论 复制链接分享
  • u014629433 胖子程序员 5年前

    贴一下错误提示谢谢。log

    点赞 评论 复制链接分享
  • andysern andysern 5年前

    补充一下JSP页面的

    <%@ page contentType="text/html; charset=GBK"
    import="java.util.*,com.jspsmart.upload.*"%>
    <%@ page import="inhome.IPTimeStamp" %>

    。。。。

    String ip = request.getHeader("x-forwarded-for");
    if(null == ip || 0 == ip.length() || "unknown".equalsIgnoreCase(ip)) {
        ip = request.getHeader("Proxy-Client-IP");
    }
    if(null == ip || 0 == ip.length() || "unknown".equalsIgnoreCase(ip)) {
        ip = request.getHeader("WL-Proxy-Client-IP");
    }
    if(null == ip || 0 == ip.length() || "unknown".equalsIgnoreCase(ip)) {
        ip = request.getHeader("X-Real-IP");
    }
    if(null == ip || 0 == ip.length() || "unknown".equalsIgnoreCase(ip)) {
        ip = request.getRemoteAddr();
    }
    

    out.println("文件来自于 ip:"+ip);

    getIpName.setIPTimeStmap(ip); //只要没有这句,就不会报错

    out.println(getIpName.getIPTimeRand()); //没有上面一句,这里能得到正确的结果。

    点赞 评论 复制链接分享

相关推荐