Search...
FAQs
Subscribe
Pie
FAQs
Recent topics
Flagged topics
Hot topics
Best topics
Search...
Search within Servlets
Search Coderanch
Advance search
Google search
Register / Login
Post Reply
Bookmark Topic
Watch Topic
New Topic
programming forums
Java
Mobile
Certification
Databases
Caching
Books
Engineering
Micro Controllers
OS
Languages
Paradigms
IDEs
Build Tools
Frameworks
Application Servers
Open Source
This Site
Careers
Other
Pie Elite
all forums
this forum made possible by our volunteer staff, including ...
Marshals:
Campbell Ritchie
Jeanne Boyarsky
Ron McLeod
Paul Clapham
Liutauras Vilda
Sheriffs:
paul wheaton
Rob Spoor
Devaka Cooray
Saloon Keepers:
Stephan van Hulst
Tim Holloway
Carey Brown
Frits Walraven
Tim Moores
Bartenders:
Mikalai Zaikin
Forum:
Servlets
package javax.servlet.annotation does not exist
Farakh khan
Ranch Hand
Posts: 851
posted 12 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
Hello,
I am facing the following error while compiling the code:
C:\Program Files (x86)\Java\Tomcat7.2\webapps\ROOT\WEB-INF\classes>javac FileUpl oad.java FileUpload.java:9: package javax.servlet.annotation does not exist import javax.servlet.annotation.WebServlet; ^ FileUpload.java:30: cannot find symbol symbol: class WebServlet @WebServlet(name="FileUpload", urlPatterns={"/FileUpload"}) ^ FileUpload.java:154: warning: sun.misc.BASE64Encoder is Sun proprietary API and may be removed in a future release String encodedString = new sun.misc.BASE64Encoder().encode(fileConten t); // changes done. ^ Note: FileUpload.java uses unchecked or unsafe operations. Note: Recompile with -Xlint:unchecked for details. 2 errors 1 warning C:\Program Files (x86)\Java\Tomcat7.2\webapps\ROOT\WEB-INF\classes>
One company sent me the code to make a
soap
request but unable to compile it. Here is the code:
/* * To change this template, choose Tools | Templates * and open the template in the editor. */ import java.net.URL; import java.net.URLConnection; import javax.servlet.ServletException; import javax.servlet.annotation.WebServlet; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpSession; import java.io.*; import java.util.ArrayList; import java.util.HashMap; import java.util.Hashtable; import java.util.List; import javax.servlet.RequestDispatcher; import javax.servlet.ServletConfig; import javax.swing.JOptionPane; import org.w3c.dom.*; import org.xml.sax.*; import javax.xml.parsers.*; /** * * @author gurdev */ @WebServlet(name="FileUpload", urlPatterns={"/FileUpload"}) public class FileUpload extends HttpServlet { private static final String DESTINATION_DIR_PATH ="ResumeUpload/"; String TMP_DIR_PATH = "tmp1"; File tmpDir; String DESTINATION_DIR_PATH1 ="Config/"; File destinationDir; public void init(ServletConfig config) throws ServletException { super.init(config); tmpDir = new File(TMP_DIR_PATH); if(!tmpDir.isDirectory()) { tmpDir.mkdir(); //throw new ServletException(TMP_DIR_PATH + " is not a directory"); } String realPath = getServletContext().getRealPath(DESTINATION_DIR_PATH1); destinationDir = new File(realPath); if(!destinationDir.isDirectory()) { destinationDir.mkdir(); //throw new ServletException(DESTINATION_DIR_PATH1+" is not a directory"); } } public HashMap readXmlDocument(Document xmlDocument) { HashMap resumeDetails = new HashMap(); try { xmlDocument.getDocumentElement().normalize(); NodeList profile = xmlDocument.getElementsByTagName("ResumeParserData"); if (profile.getLength() > 0) { Node profileNode = profile.item(0); if (profileNode.getNodeType() == Node.ELEMENT_NODE) { Element profileElement = (Element) profileNode; NodeList list = profileElement.getChildNodes(); String nodeName = ""; int j = 1; for (int i = 0; i < list.getLength(); i++) { profileNode = list.item(i); if (profileNode.getNodeType() == Node.ELEMENT_NODE) { //System.out.println(profileNode.getNodeName()); nodeName = profileNode.getNodeName(); if (profileNode.getFirstChild() != null) { //System.out.println(j++ + "). " + nodeName); // System.out.println(profileNode.getFirstChild().getNodeValue()); resumeDetails.put(nodeName, profileNode.getFirstChild().getNodeValue()); // JOptionPane.showMessageDialog(null, nodeName +"="+profileNode.getFirstChild().getNodeValue()); } } } } } } catch (Exception e) { System.out.println(e); } return resumeDetails; } public void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { // response.setContentType("text/plain"); response.setContentType("text/html;charset=UTF-8"); PrintWriter out = response.getWriter(); HttpSession ssa=request.getSession(); String sst=(String) ssa.getAttribute("ss"); String Key=(String) ssa.getAttribute("TxtKey"); String Country=(String) ssa.getAttribute("TxtCountry"); String version=(String) ssa.getAttribute("Txtversion"); String SubKey=(String) ssa.getAttribute("TextSubKey"); String Services=(String) ssa.getAttribute("TxtService"); String realPath12 = getServletContext().getRealPath(DESTINATION_DIR_PATH1); File file = new File(realPath12+"/config.mf"); if(!file.exists()){ if (file.createNewFile()){ System.out.println("Success!"); }else{ System.out.println("Error, file already exists."); } FileOutputStream fop=new FileOutputStream(file); if(file.exists()){ fop.write(Services.getBytes()); //fop.write(str1.getBytes()); fop.flush(); fop.close(); System.out.println("The data has been written"); } else System.out.println("This file is not exist"); } else{ FileOutputStream fop=new FileOutputStream(file); if(file.exists()){ fop.write(Services.getBytes()); //fop.write(str1.getBytes()); fop.flush(); fop.close(); System.out.println("The data has been written"); } else System.out.println("This file is not exist"); } try { String realPath1 = getServletContext().getRealPath(DESTINATION_DIR_PATH); String real=realPath1+"\\"+sst; File f = new File(real); FileInputStream fin = new FileInputStream(f); byte[] fileContent = new byte[(int)f.length()]; fin.read(fileContent); String encodedString = new sun.misc.BASE64Encoder().encode(fileContent); // changes done. StringBuffer soapXML = new StringBuffer(); soapXML.append("<?xml version='1.0' encoding='utf-8'?>"); soapXML.append( "<soap:Envelope xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xmlns:xsd='http://www.w3.org/2001/XMLSchema' xmlns:soap='http://schemas.xmlsoap.org/soap/envelope/'>"); soapXML.append("<soap:Body>"); soapXML.append("<ParseResumeBinary xmlns='http://tempuri.org/'>"); soapXML.append("<filedata>"+encodedString+"</filedata>"); soapXML.append("<filetype>doc</filetype>"); soapXML.append("<key>"+Key+"</key>"); soapXML.append("<version>"+version+"</version>"); soapXML.append("<countryKey>"+Country+"</countryKey>"); soapXML.append("<subuserKey>"+SubKey+"</subuserKey>"); soapXML.append("</ParseResumeBinary>"); soapXML.append("</soap:Body>"); soapXML.append("</soap:Envelope>"); URL url = new URL (Services) ; //correction done URLConnection urlc = url.openConnection(); urlc.setRequestProperty("SOAPAction","http://tempuri.org/ParseResumeBinary"); //correction done urlc.setRequestProperty("Content-Type","text/xml;charset=utf-8"); DataOutputStream printout ; //= urlc.getOutputStream (); // Let the run-time system (RTS) know that we want input. urlc.setDoInput ( true ) ; // Let the RTS know that we want to do output. urlc.setDoOutput ( true ) ; printout = new DataOutputStream ( urlc.getOutputStream ( ) ); printout.writeBytes ( soapXML.toString() ) ; printout.flush ( ) ; printout.close ( ) ; InputStream in = urlc.getInputStream(); BufferedReader is= new BufferedReader(new InputStreamReader(in)); String line = ""; StringBuffer str=new StringBuffer(); while((line = is.readLine())!= null) { System.out.println(line); str.append(line); } System.out.println(str.toString()); String ss1=str.toString(); String ssp= ss1.replace("<", "<"); String ssp1=ssp.replace(">", ">"); String strXml=ssp1.substring(298); DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); DocumentBuilder db = dbf.newDocumentBuilder(); InputSource is1 = new InputSource(); is1.setCharacterStream(new StringReader(ssp1)); Document dom = db.parse(is1); FileUpload xmldom=new FileUpload(); HashMap resumeDetails = xmldom.readXmlDocument(dom); RequestDispatcher dispatcher = request.getRequestDispatcher("parseFrame.jsp"); request.setAttribute("resume", resumeDetails); request.setAttribute("ss1", ss1); //System.out.println(currentDate.concat("_").concat(fileName)); dispatcher.forward(request, response); } catch (Exception ex ) { System.out.print(ex.getMessage()); } } // <editor-fold defaultstate="collapsed" desc="HttpServlet methods. Click on the + sign on the left to edit the code."> /** * Handles the HTTP <code>GET</code> method. * @param request servlet request * @param response servlet response * @throws ServletException if a servlet-specific error occurs * @throws IOException if an I/O error occurs */ @Override protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { processRequest(request, response); } /** * Handles the HTTP <code>POST</code> method. * @param request servlet request * @param response servlet response * @throws ServletException if a servlet-specific error occurs * @throws IOException if an I/O error occurs */ @Override protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { processRequest(request, response); } /** * Returns a short description of the servlet. * @return a String containing servlet description */ @Override public String getServletInfo() { return "Short description"; }// </editor-fold> }
Thanks & best regards
bhanu chowdary
Ranch Hand
Posts: 256
posted 12 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
What is the version of
servlet
api you are using??
WebServlet
exists since 3.0
Farakh khan
Ranch Hand
Posts: 851
posted 12 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
I installed
Tomcat
7.2.0 and this is fixed. Thanks for your assistance
Don't get me started about those stupid
light bulbs
.
reply
reply
Bookmark Topic
Watch Topic
New Topic
Boost this thread!
Similar Threads
Using commons-fileupload-1.2.1.jar to upload file to MySQL
servlet mapping
Problem to call servlet from Java class
HTTP Status 404 -
175: warning: BASE64Encoder is internal proprietary API and m ay be removed in a future release
More...