Tomcat JSP错误500

时间:2015-06-16 13:16:26

标签: java html jsp tomcat

我遇到过这个奇怪的错误,现在我将解释这种情况发生的时间: 基本上我要做的是使用一个简单的文本字段和两个按钮来创建一个HTML表单(或JSP,并不重要),一个用于提交到.jsp页面,另一个用于重置文本字段。 一切都运行正常,除非我尝试在文本字段中写入带空格的东西(例如:" abc 123")。 如果我只是写" abc123"但它并没有给出任何错误500.

我希望你们中的一些人可以帮助我,这里有消息来源:

<html>
    <head>`<html>
<head>
<meta charset="ISO-8859-1">
<title>HTML Form</title>
</head>
<body>
    <form name = "intoll" method = "post" action = "send.jsp">
        Insert text: <input type = "text" name = "food" id = "food">
        <br/>
        <input type = "submit" name = "send" value = "Send">
        <input type = "reset" name = "Reset">
    </form>
</body>

send.jsp:

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<%@ page import="com.athirat.intolleranze.foods.*" %>
<%
    String food = request.getParameter("food").trim();
    if (food != null && food != "") {
        food = food.toLowerCase();
        out.print(food);
        NetMaster.init(food);
    }
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
    </head>
    <body>
        <% 
            try {
                out.print(NetMaster.showContent());
            } catch (Exception e) {
                throw new Exception("String error");
            }
        %>
        </body>
    </html>

感谢您的帮助。

编辑: 栈跟踪

giu 16, 2015 3:06:12 PM org.apache.catalina.core.StandardWrapperValve invoke
GRAVE: Servlet.service() for servlet [jsp] in context with path [/intoll] threw exception [An exception occurred processing JSP page /send.jsp at line 22

19:         try {
20:             out.print(NetMaster.showContent());
21:         } catch (Exception e) {
22:             throw new Exception("String error");
23:         }
24:     %>
25: </body>


Stacktrace:] with root cause
java.lang.Exception: Errore nella stringa
at org.apache.jsp.send_jsp._jspService(send_jsp.java:113)
    at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:438)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:396)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:340)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:291)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:219)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:106)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:502)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:142)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79)
at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:617)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:88)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:518)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1091)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:668)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1521)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:1478)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
at java.lang.Thread.run(Unknown Source)

giu 16, 2015 3:23:56 PM org.apache.catalina.core.StandardWrapperValve invoke
GRAVE: Servlet.service() for servlet [jsp] in context with path [/intoll] threw exception [An exception occurred processing JSP page /send.jsp at line 22

19:         try {
20:             out.print(NetMaster.showContent());
21:         } catch (Exception e) {
22:             throw new Exception("String error");
23:         }
24:     %>
25: </body>


Stacktrace:] with root cause
java.lang.Exception: Errore nella stringa
at org.apache.jsp.send_jsp._jspService(send_jsp.java:113)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:438)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:396)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:340)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:291)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:219)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:106)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:502)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:142)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79)
at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:617)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:88)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:518)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1091)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:668)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1521)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:1478)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
at java.lang.Thread.run(Unknown Source)

这是方法showContent,它被称为方法:

public static String showContent() throws Exception {
        if (isFood())
            return getContent();
        else 
            return "LOG Creato: " + generateLogFile();
    }
    private static String generateLogFile() throws Exception {
        Calendar cal = Calendar.getInstance();
        SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmss");
        String logname = "foodLog_" + sdf.format(cal.getTime());
        String logdir = ps.getProperty("logfolder");
        File f = new File ("." + logdir + logname + ".log");
        FileOutputStream fout = new FileOutputStream(f);
        DataOutputStream dout = new DataOutputStream(fout);
        System.out.println(logname);
        System.out.println(logdir);
        System.out.println(f.getParent());
        dout.writeBytes(food + " non esistente, si prega di aggiungerlo");
        fout.close();
        return logname;
    }
    private static String getContent() {
        String result = "{[";
        @SuppressWarnings("resource")
        Scanner sc = new Scanner(inputReader).useDelimiter("\\A");
        result += sc.hasNext() ? sc.next() : "";
        return result;
    }

1 个答案:

答案 0 :(得分:0)

我解决了: showContent()抛出一个Exception,我只需要抓住它。 这个错误是因为我曾经在showContent()的try-catch中抛出一个新异常,这是我无法做到的。 谢谢大家。