kisonlee 2009-08-27 21:09
浏览 310
已采纳

在struts2的simple主题下,如何才能显示拦截错误信息呢

在struts2的simple主题下,如何才能显示拦截错误信息呢,我不太想用xhtml,这样我的样式只能按它固定的了。。。。
[b]问题补充:[/b]
关键我jsp使用struts标签写的。。。。。
[b]问题补充:[/b]
另外问大家个问题,我上传图片,当非指定格式和大小时,jsp就挂了

upload.jsp
[code="java"]<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<%@taglib prefix="s" uri="/struts-tags"%>

function checkFile() { if(document.getElementById("upload1").value == "") { alert("请选择封面图片!"); return false; } else if(document.getElementById("upload2").value == "") { alert("请选择封底图片!"); return false; } else return true; }





上传教材图片







第三步:上传教材图片



/s:fielderror




/s:form







[/code]

Spread.java
[code="java"]package action;

import java.awt.image.BufferedImage;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.Date;
import javax.imageio.ImageIO;
import org.apache.struts2.ServletActionContext;
import bean.DBUtil;
import com.opensymphony.xwork2.ActionSupport;

public class Spread extends ActionSupport
{
private static final long serialVersionUID = 1L;

public File[] getUpload()
{
    return upload;
}
public void setUpload(File[] upload)
{
    this.upload = upload;
}
public String[] getUploadContentType()
{
    return uploadContentType;
}
public void setUploadContentType(String[] uploadContentType)
{
    this.uploadContentType = uploadContentType;
}
public String[] getUploadFileName()
{
    return uploadFileName;
}
public void setUploadFileName(String[] uploadFileName)
{
    this.uploadFileName = uploadFileName;
}
public String getSavePath()
{ 
   return ServletActionContext.getServletContext().getRealPath(savePath); 
} 
public void setSavePath(String savePath) 
{ 
    this.savePath = savePath; 
}

public void validateThirdStep()
{
    clearErrorsAndMessages();
    File [] files = getUpload();
    BufferedImage image = null;
    for (int i = 0; i < files.length; i++)
    {
        try
        {
            image = ImageIO.read(files[i]);
        } catch(IOException e)
        {
            e.printStackTrace();
        }

        if (image.getWidth() > 260 || image.getHeight() > 260)
        {
            addFieldError("picSizeErr", "上传图片宽高不能超过260*260");
            break;
        }
    }
}

public String excute() throws Exception
{
    String imageFileName;
    File[] files = getUpload();
    for (int i = 0 ; i < files.length ; i++)
    {
        imageFileName = new Date().getTime() + getUploadFileName()[i].substring(getUploadFileName()[i].lastIndexOf("."));
        realPath[i] = getSavePath() + "\\" + imageFileName;
        FileOutputStream fos = null;
        FileInputStream fis = null;
        try
        {
            fos = new FileOutputStream(getSavePath() + "\\" + imageFileName);
            fis = new FileInputStream(files[i]);
        } 
        catch(FileNotFoundException e)
        {
            e.printStackTrace();
        }

        byte[] buffer = new byte[BUFFER_SIZE];
        int len = 0;
        try
        {
            while ((len = fis.read(buffer)) > 0)
            {
                fos.write(buffer , 0 , len);
            }
        } 
        catch(IOException e)
        {
            e.printStackTrace();
        }
        finally
        {
            fis.close();
            fos.close();
        }
    }
    return SUCCESS;
}


private static final int BUFFER_SIZE = 16 * 1024;
private File[] upload;
private String[] uploadContentType;
private String[] uploadFileName;
private String savePath;
private String [] realPath = new String[2];

}
[/code]

struts.xml
[code="java"]<?xml version="1.0" encoding="utf-8" ?>

<!DOCTYPE struts PUBLIC

"-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"

"http://struts.apache.org/dtds/struts-2.0.dtd">






/spread/spread1.jsp
/login.jsp

<package name="authority" extends="struts-default">
    <interceptors>
        <interceptor name="authority" class="interceptor.AuthorityInterceptor" />
    </interceptors>

    <default-interceptor-ref name="authority" />

    <global-results>
        <result name="login">/login.jsp</result>
    </global-results>


    <action name="ThirdStep" class="action.Spread">
        <result name="success">/spread/spread4.jsp </result>
        <result name="input">/spread/upload.jsp </result>
        <interceptor-ref name="fileUpload">
            <param name="allowedTypes">image/jpeg,image/pjpeg</param>
            <param name="maximumSize">204800</param>
        </interceptor-ref>

        <param name="savePath">/upload</param>
    </action>   
</package>



[/code]
异常信息jsp:
type Exception report

message

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

exception

java.lang.NullPointerException
action.Spread.thirdStep(Spread.java:285)--(这句for (int i = 0 ; i < files.length ; i++))
sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
java.lang.reflect.Method.invoke(Unknown Source)
com.opensymphony.xwork2.DefaultActionInvocation.invokeAction(DefaultActionInvocation.java:440)
com.opensymphony.xwork2.DefaultActionInvocation.invokeActionOnly(DefaultActionInvocation.java:279)
com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:242)
org.apache.struts2.interceptor.FileUploadInterceptor.intercept(FileUploadInterceptor.java:306)
com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:236)
org.apache.struts2.impl.StrutsActionProxy.execute(StrutsActionProxy.java:52)
org.apache.struts2.dispatcher.Dispatcher.serviceAction(Dispatcher.java:468)
org.apache.struts2.dispatcher.FilterDispatcher.doFilter(FilterDispatcher.java:395)
filter.SetCharacterEncodingFilter.doFilter(SetCharacterEncodingFilter.java:33)

[b]问题补充:[/b]
我这个只能是JPG的,大小不能超过200KB,按要求可以正常上传,可是如果非jpg或者大于200KB,拦截器可以发现,但是jsp页面就挂了,不知道为啥,控制台不显示异常信息
[b]问题补充:[/b]
walsh

按你说的,如果在submit中添加simple,到时可以和reset一行,可是两个按键全部跑到真个table的最上面边了,这是个问题,你可以看看

<%@ page contentType="text/html; charset=utf-8" language="java" import="java.sql.*,java.util.*" errorPage="" %>
<%@taglib prefix="s" uri="/struts-tags"%>
<%@taglib prefix="sx" uri="/struts-dojo-tags"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

function trim(s) { return s.replace(/^\s*/,"").replace(/\s*$/,""); } function validate() { var value; for(i = 1;i <= 13;i++) { value = trim(document.getElementById('item' + i).value); if(value == "" || value == null) { alert('请填写相关项!'); return false; } } return true; }






创建教材信息

第二步:创建教材信息
教材尺寸:
编著时间:
发行时间:



  • 写回答

6条回答 默认 最新

  • walsh_bupt 2009-08-28 00:07
    关注

    [size=medium] 你把theme="simple"放到submit里边干嘛呢,我是说你把它放到form标签中,就像下边这样:

    [/size]

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(5条)

报告相同问题?

悬赏问题

  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 对于相关问题的求解与代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料