jjzjj

java - WebServlet 无法解析为类型

coder 2024-03-17 原文

<分区>

按照 user2821894 的建议,我能够使我的应用程序再次运行,但在尝试调用 servlet tomcat 7 后再次停止运行!! 如果我尝试删除调用我的 servlet 的代码,我的网络应用程序就无法正常工作!! 一旦我有一个 servlet tomcat 停止工作的问题。

我在 eclipse 上启动我的 web 项目时遇到了问题。我在使用 Tomcat 7 时遇到了问题。 所以我从 eclipse 中“删除”了 tomcat 7,然后我再次添加了它(再次是 tomcat 7)。

现在我启动我的 web 项目没有问题,但我的 servlet 有问题。 例如我收到类似

的错误
 WebServlet cannot be resolved to a type
 The attribute value is undefined for the annotation type 

我将 servlet-api 3.0.jar 添加到我的项目中,但我仍然遇到这些问题。

这是我的servlet的代码

 package Jeans;
    import java.io.IOException;
    import java.io.InputStream;
    import java.sql.Connection;
    import java.sql.PreparedStatement;
    import java.sql.SQLException;

    import javax.servlet.ServletException;
    import javax.servlet.http.HttpServlet;
    import javax.servlet.http.HttpServletRequest;
    import javax.servlet.http.HttpServletResponse;
    import javax.servlet.annotation.WebServlet;

    import com.sun.java.swing.plaf.windows.TMSchema.Part;


    import javax.servlet.http.Part;



    @WebServlet("/FileUploadDBServlet ")

  //// i got an error here//////////////////////////// 
    @MultipartConfig(maxFileSize = 16177215)  

    public class FileUploadDBServlet extends HttpServlet {


        private String dbURL = "db";
        private String dbUser = "dbuser";
        private String dbPass = "dbpassword";
        String messageMio = "da contorllare";  
        GestioneDB gestioneDB;
        boolean connessione;       
        Connection conn;

        protected void doPost(HttpServletRequest request,
                HttpServletResponse response) throws ServletException, IOException {




         String giorno= request.getParameter("giorno");
         String mese= request.getParameter("mese");
         String anno= request.getParameter("anno");         
         String dataFormatoItaliano = giorno + "-" + mese + "-" + anno;     

          String titolo = request.getParameter("titolo");
          String titoletto = request.getParameter("titoletto");
          String testoMouse = request.getParameter("testoMouse");
          String link = request.getParameter("link");
          String data = dataFormatoItaliano;
          String testo = request.getParameter("testo");




          //// i got an error here////////////////////////////
          Part filePart = request.getPart("immaginePrincipale");  






 String didascaliaImmaginePrincipale = request.getParameter("didascaliaImmaginePrincipale");       


            InputStream immaginePrincipale = null; 
            if (filePart != null) {             
                // obtains input stream of the upload file
                immaginePrincipale = filePart.getInputStream();
            }





            String message = null;  

            try {

                  gestioneDB = new GestioneDB(); 
                  conn = gestioneDB.cn();  



                  gestioneDB.inserimentoNews(titolo, titoletto, testoMouse, link, testo, data, immaginePrincipale, didascaliaImmaginePrincipale);



                String sql = "INSERT INTO allegati_news (allegato,didascalia,tipo,id_news,immagine) values (?,?,?,?,?)";




                PreparedStatement statement = conn.prepareStatement(sql);
                statement.setString(1, "firstName");
                statement.setString(2, "lastName");
                statement.setInt(3, 1);
                statement.setInt(4,1);            
                if (immaginePrincipale != null) {              
                    statement.setBlob(5, immaginePrincipale);             
                }




                int row = statement.executeUpdate();
                if (row > 0) {
                    message = "File salvato nel db";
                }
            } catch (SQLException ex) {
                message = "ERROR: " + ex.getMessage();
                ex.printStackTrace();
            } finally {
                if (conn != null) {

                    try {
                        conn.close();
                    } catch (SQLException ex) {
                        ex.printStackTrace();
                    }
                }

               request.setAttribute("Message", gestioneDB.getInserimentoNewMessaggio());



               getServletContext().getRequestDispatcher("/Message.jsp").forward(request, response);
            }
        }
    }

这是我的 web.xml 文件

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5">
  <display-name>Jeans2</display-name>
  <welcome-file-list>
    <welcome-file>index.html</welcome-file>
    <welcome-file>index.htm</welcome-file>
    <welcome-file>index.jsp</welcome-file>
    <welcome-file>default.html</welcome-file>
    <welcome-file>default.htm</welcome-file>
    <welcome-file>default.jsp</welcome-file>
  </welcome-file-list>
  <servlet>
    <description></description>
    <display-name>prova</display-name>
    <servlet-name>prova</servlet-name>
    <servlet-class>Jeans.prova</servlet-class>
  </servlet>
  <servlet-mapping>
    <servlet-name>prova</servlet-name>
    <url-pattern>/prova</url-pattern>
  </servlet-mapping>
  <servlet>

    <description></description>
    <display-name>FileUploadDBServlet</display-name>
    <servlet-name>FileUploadDBServlet</servlet-name>
    <servlet-class>Jeans.FileUploadDBServlet</servlet-class>
  </servlet>
  <servlet-mapping>
    <servlet-name>FileUploadDBServlet</servlet-name>
    <url-pattern>/FileUploadDBServlet</url-pattern>
  </servlet-mapping>

   <servlet>
    <description></description>
    <display-name>BlobDisplay</display-name>
    <servlet-name>BlobDisplay</servlet-name>
    <servlet-class>Jeans.BlobDisplay</servlet-class>
  </servlet>
  <servlet-mapping>
    <servlet-name>BlobDisplay</servlet-name>
    <url-pattern>/BlobDisplay</url-pattern>
  </servlet-mapping>


</web-app>

有关java - WebServlet 无法解析为类型的更多相关文章

  1. Ruby 解析字符串 - 2

    我有一个字符串input="maybe(thisis|thatwas)some((nice|ugly)(day|night)|(strange(weather|time)))"Ruby中解析该字符串的最佳方法是什么?我的意思是脚本应该能够像这样构建句子:maybethisissomeuglynightmaybethatwassomenicenightmaybethiswassomestrangetime等等,你明白了......我应该一个字符一个字符地读取字符串并构建一个带有堆栈的状态机来存储括号值以供以后计算,还是有更好的方法?也许为此目的准备了一个开箱即用的库?

  2. ruby-on-rails - 由于 "wkhtmltopdf",PDFKIT 显然无法正常工作 - 2

    我在从html页面生成PDF时遇到问题。我正在使用PDFkit。在安装它的过程中,我注意到我需要wkhtmltopdf。所以我也安装了它。我做了PDFkit的文档所说的一切......现在我在尝试加载PDF时遇到了这个错误。这里是错误:commandfailed:"/usr/local/bin/wkhtmltopdf""--margin-right""0.75in""--page-size""Letter""--margin-top""0.75in""--margin-bottom""0.75in""--encoding""UTF-8""--margin-left""0.75in""-

  3. ruby - 解析 RDFa、微数据等的最佳方式是什么,使用统一的模式/词汇(例如 schema.org)存储和显示信息 - 2

    我主要使用Ruby来执行此操作,但到目前为止我的攻击计划如下:使用gemsrdf、rdf-rdfa和rdf-microdata或mida来解析给定任何URI的数据。我认为最好映射到像schema.org这样的统一模式,例如使用这个yaml文件,它试图描述数据词汇表和opengraph到schema.org之间的转换:#SchemaXtoschema.orgconversion#data-vocabularyDV:name:namestreet-address:streetAddressregion:addressRegionlocality:addressLocalityphoto:i

  4. ruby - 用逗号、双引号和编码解析 csv - 2

    我正在使用ruby​​1.9解析以下带有MacRoman字符的csv文件#encoding:ISO-8859-1#csv_parse.csvName,main-dialogue"Marceu","Giveittohimóhe,hiswife."我做了以下解析。require'csv'input_string=File.read("../csv_parse.rb").force_encoding("ISO-8859-1").encode("UTF-8")#=>"Name,main-dialogue\r\n\"Marceu\",\"Giveittohim\x97he,hiswife.\"\

  5. ruby-on-rails - 无法使用 Rails 3.2 创建插件? - 2

    我对最新版本的Rails有疑问。我创建了一个新应用程序(railsnewMyProject),但我没有脚本/生成,只有脚本/rails,当我输入ruby./script/railsgeneratepluginmy_plugin"Couldnotfindgeneratorplugin.".你知道如何生成插件模板吗?没有这个命令可以创建插件吗?PS:我正在使用Rails3.2.1和ruby​​1.8.7[universal-darwin11.0] 最佳答案 随着Rails3.2.0的发布,插件生成器已经被移除。查看变更日志here.现在

  6. ruby - 无法运行 Rails 2.x 应用程序 - 2

    我尝试运行2.x应用程序。我使用rvm并为此应用程序设置其他版本的ruby​​:$rvmuseree-1.8.7-head我尝试运行服务器,然后出现很多错误:$script/serverNOTE:Gem.source_indexisdeprecated,useSpecification.Itwillberemovedonorafter2011-11-01.Gem.source_indexcalledfrom/Users/serg/rails_projects_terminal/work_proj/spohelp/config/../vendor/rails/railties/lib/r

  7. ruby-on-rails - 无法在centos上安装therubyracer(V8和GCC出错) - 2

    我正在尝试在我的centos服务器上安装therubyracer,但遇到了麻烦。$geminstalltherubyracerBuildingnativeextensions.Thiscouldtakeawhile...ERROR:Errorinstallingtherubyracer:ERROR:Failedtobuildgemnativeextension./usr/local/rvm/rubies/ruby-1.9.3-p125/bin/rubyextconf.rbcheckingformain()in-lpthread...yescheckingforv8.h...no***e

  8. ruby - 无法让 RSpec 工作—— 'require' : cannot load such file - 2

    我花了三天的时间用头撞墙,试图弄清楚为什么简单的“rake”不能通过我的规范文件。如果您遇到这种情况:任何文件夹路径中都不要有空格!。严重地。事实上,从现在开始,您命名的任何内容都没有空格。这是我的控制台输出:(在/Users/*****/Desktop/LearningRuby/learn_ruby)$rake/Users/*******/Desktop/LearningRuby/learn_ruby/00_hello/hello_spec.rb:116:in`require':cannotloadsuchfile--hello(LoadError) 最佳

  9. ruby - Infinity 和 NaN 的类型是什么? - 2

    我可以得到Infinity和NaNn=9.0/0#=>Infinityn.class#=>Floatm=0/0.0#=>NaNm.class#=>Float但是当我想直接访问Infinity或NaN时:Infinity#=>uninitializedconstantInfinity(NameError)NaN#=>uninitializedconstantNaN(NameError)什么是Infinity和NaN?它们是对象、关键字还是其他东西? 最佳答案 您看到打印为Infinity和NaN的只是Float类的两个特殊实例的字符串

  10. ruby - 检查方法参数的类型 - 2

    我不确定传递给方法的对象的类型是否正确。我可能会将一个字符串传递给一个只能处理整数的函数。某种运行时保证怎么样?我看不到比以下更好的选择:defsomeFixNumMangler(input)raise"wrongtype:integerrequired"unlessinput.class==FixNumother_stuffend有更好的选择吗? 最佳答案 使用Kernel#Integer在使用之前转换输入的方法。当无法以任何合理的方式将输入转换为整数时,它将引发ArgumentError。defmy_method(number)

随机推荐