Question

In: Computer Science

I kept getting errors trying to make this code to work, can someone show me what...

I kept getting errors trying to make this code to work, can someone show me what i am doing wrong?

import javax.servlet.*;

import javax.servlet.http.*;

import javax.servlet.annotation.*;

import java.io.*;

import java.util.*;

import java.nio.file.*;

import java.nio.charset.*;

import java.util.*;


//@WebServlet(name = "Assignment3_1", urlPatterns = { "/ReadFile" })
public class ReadFile extends HttpServlet{
static Charset myCharset = Charset.forName("US-ASCII");


@Override public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException{

response.setContentType("text/html");


PrintWriter printer = response.getWriter();
out.println("<html>");

out.println("<head>");

out.println("<title>");

out.println("Assignment 5.1");

out.println("</title>");

out.println("<h1>Is Bitcoin money?</h1>");

out.println("</head>");

out.println("<body>");

out.println("<div>");

writeAndReadFile(printer);

out.println("</div>");

out.println("</body>");

out.println("</html>");

}
private synchronized void writeAndReadFile(PrintWriter out){
try{

Path file = Paths.gets("C:/Temp/servlet1.dat");
List <String> linesReads = null;
// Read every line in the .dat file.

linesRead = Files.readAllLine(file, myCharset);   
if(linesRead is null){
for(String line : linesRead){
out.println(line + "<br />\n");

}

}

}

catch(IOException e)

{
out.println("ERROR* >> "); out.println(e.toString());
}

}

}

Solutions

Expert Solution

/* WRONG STATEMENT IN YOUR CODE WAS */

wrong: PrintWriter printer = response.getWriter();

correct: PrintWriter out = response.getWriter(); // since you use out for println statement

wrong: writeAndReadFile(printer);

correct: writeAndReadFile(out);//PASS OUT

wrong: Path file = Paths.gets("C:/Temp/servlet1.dat");

correct : Path file = Paths.get("C:/Temp/servlet1.dat");//get is method

wrong: linesRead = Files.readAllLine(file, myCharset);

correct: linesReads = Files.readAllLine(file, myCharset); // since you create variable linesReads

if(linesReads == null){
for(String line : linesReads){
out.println(line + "<br />\n");

/* Match your code from Screenshot */

/* OUTPUT */

/* SINCE I HAVE NO FILE SERVER1.DAT */

/* PLEASE UPVOTE */


Related Solutions

I am getting 7 errors can someone fix and explain what I did wrong. My code...
I am getting 7 errors can someone fix and explain what I did wrong. My code is at the bottom. Welcome to the DeVry Bank Automated Teller Machine Check balance Make withdrawal Make deposit View account information View statement View bank information Exit          The result of choosing #1 will be the following:           Current balance is: $2439.45     The result of choosing #2 will be the following:           How much would you like to withdraw? $200.50      The...
Can someone please tell me why I am getting errors. I declared the map and it's...
Can someone please tell me why I am getting errors. I declared the map and it's values like instructed but it's telling me I'm wrong. #include <iostream> #include <stdio.h> #include <time.h> #include <chrono> #include <string> #include <cctype> #include <set> #include <map> #include "d_state.h" using namespace std; int main() { string name; map<string,string> s; map<string,string>::iterator it; s[“Maryland”] = "Salisbury"; s[“Arizona”] = "Phoenix"; s[“Florida”] = "Orlando"; s[“Califonia”] = "Sacramento"; s[“Virginia”] = "Richmond"; cout << "Enter a state:" << endl; cin >> name;...
Okay, can someone please tell me what I am doing wrong?? I will show the code...
Okay, can someone please tell me what I am doing wrong?? I will show the code I submitted for the assignment. However, according to my instructor I did it incorrectly but I am not understanding why. I will show the instructor's comment after providing my original code for the assignment. Thank you in advance. * * * * * HourlyTest Class * * * * * import java.util.Scanner; public class HourlyTest {    public static void main(String[] args)     {        ...
can someone make me a shopping cart for me ? i need to make a shopping...
can someone make me a shopping cart for me ? i need to make a shopping cart ,but i have no idea about how to do this i have made 3 line of items , this is one of the pruduct line line 1 ------------------------------------- <!DOCTYPE html> <html lang="en"> <head> <style> .div1 { border: 2px outset red; background-color: lightblue; text-align: center; } </style> </head> <!-- body --> <body style="background-color:silver; "class="main-layout position_head"> <!-- loader --> </li> </ul> </section> </nav> </section> </header>...
can someone please answer for me that quaestions. please make sure that i understand your work...
can someone please answer for me that quaestions. please make sure that i understand your work and handwriting. thank you _____________________________________________________ 1. We will sketch some quadrics, but in order to make sure our graphs have some accuracy, we will project the surfaces onto the 3 coordinate planes. For each equation, draw four separate graphs for the surface S: i. the projection of S onto the xy-plane, ii. the projection of S onto the xz-plane, iii. the projection of S...
Could someone please tell me what corrections I should make to this code. (Python) Here are...
Could someone please tell me what corrections I should make to this code. (Python) Here are the instructions. Modify the program so it contains four columns: name, year, price and rating (G,PG,R…) Enhance the program so it provides a find by rating function that lists all of the movies that have a specified rating I can't get the find function to work and I have no idea how to even go about it. For example, when type in 'find' and...
Can someone show me the R code to accomplish this? In R, Construct scatter plots of...
Can someone show me the R code to accomplish this? In R, Construct scatter plots of y versus x, y versus ln(x), ln(y) versus ln(x) and 1/y versus 1/x. Include your R code in a separate file. The article “Reduction in Soluble Protein and Chlorophyll Contents in a Few Plants as Indicators of Automobile Exhaust Pollution” (Intl. J. of Environ. Studies, 1983: 239-244) reported the accompanying data on x distance from a highway (meters) and y lead content of soil...
can someone tell me why I'm getting the error code on Eclipse IDE: Error: Main method...
can someone tell me why I'm getting the error code on Eclipse IDE: Error: Main method is not static in class StaticInitializationBlock, please define the main method as:    public static void main(String[] args) This is what I'm working on class A { static int i; static { System.out.println(1); i = 100; } } public class StaticInitializationBlock { static { System.out.println(2); } public static void main(String[] args) { System.out.println(3); System.out.println(A.i); } }
Can someone please show me how to do the work on this please. Question The transactions...
Can someone please show me how to do the work on this please. Question The transactions of the Fury Delivery Service are recorded in the general journal below. Instructions: 1. Post the journal entries to the attached general ledger “T” accounts. 2. Prepare a trial balance on the form provided after the “T” accounts. General Journal Date Account Titles and Explanation Debit Credit 2017 Sept. 1 Cash Common Stock (Stockholders invested cash in business) 25,000 25,000 4 Equipment Cash Notes...
This is an Android Question. I am trying to make a FAB(Floating Action Button) show me...
This is an Android Question. I am trying to make a FAB(Floating Action Button) show me a different page when I press it.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT