We are here with you hands in hands to facilitate your learning & don't appreciate the idea of copying or replicating solutions. Read More>>

Looking For Something at vustudents.ning.com? Click Here to Search

www.bit.ly/vucodes

+ Link For Assignments, GDBs & Online Quizzes Solution

www.bit.ly/papersvu

+ Link For Past Papers, Solved MCQs, Short Notes & More

Dear all, 

I have received lot of msgs and private chat messages that students are facing problem in compiling java servlet.

The errors might be as below if you compile a servlet i.e. HelloWorldServlet

D:\java umt>javac HelloWorldServlet.java
HelloWorldServlet.java:4: error: package javax.servlet does not exist
import javax.servlet.*;
^
HelloWorldServlet.java:5: error: package javax.servlet.http does not exist
import javax.servlet.http.*;
^
HelloWorldServlet.java:6: error: cannot find symbol
public class HelloWorldServlet extends HttpServlet{
^
symbol: class HttpServlet
HelloWorldServlet.java:10: error: cannot find symbol
public void doGet(HttpServletRequest request,HttpServletResponse response) throws
^
symbol: class HttpServletRequest
location: class HelloWorldServlet
HelloWorldServlet.java:10: error: cannot find symbol
public void doGet(HttpServletRequest request,HttpServletResponse response) throws
^
symbol: class HttpServletResponse
location: class HelloWorldServlet
HelloWorldServlet.java:10: error: cannot find symbol
public void doGet(HttpServletRequest request,HttpServletResponse response) throws

symbol: class ServletException
location: class HelloWorldServlet
6 errors

 The reason behind is that it need that library (.jar) file which contains all servlet related dependencies.

TO fix this error first you need to know the location of your  tomcat for example in my case it is "d:\tomcat8"

To Compile your Servlet with notepad and command line u need to run below command javac -classpath D:\tomcat8\lib\servlet-api.jar HelloWorldServlet.java

if your tomcat is installed on D:\apache-tomcat-6.0.44

then u will compile ur servlet like

javac -classpath D:\apache-tomcat-6.0.44\lib\servlet-api.jar HelloWorldServlet.java  

in command above we are just providing compiler that servlet-api.jar file is located at particular location.

Welcome for your questions.

+ How to Join Subject Study Groups & Get Helping Material?

+ How to become Top Reputation, Angels, Intellectual, Featured Members & Moderators?

+ VU Students Reserves The Right to Delete Your Profile, If?


See Your Saved Posts Timeline

Views: 614

.

+ http://bit.ly/vucodes (Link for Assignments, GDBs & Online Quizzes Solution)

+ http://bit.ly/papersvu (Link for Past Papers, Solved MCQs, Short Notes & More)

+ Click Here to Search (Looking For something at vustudents.ning.com?)

+ Click Here To Join (Our facebook study Group)

Replies to This Discussion

HelloWorldServlet.java file ko pehle konci directory mein rakhna hai??

You can place anywhere to compile it. it will generate a HelloWorldServlet.class file. then u need to place this .class file into
/WEB-INF/classes/HelloWorldServlet.class

Main ne assignment complete ker li hai.. lakin jab main values enter ker k Solve Equation ka button press kerta hoon to error aata hai... Please see the images and let me know the problem... Thanks

This error is due to "you are using form method GET and in servlet you are using doPost method or vice versa

3 ways to solve it

1. write your code in doGet Method and use form method as GET

2. write you code in doPost method and use form metho as POST

3. create a private function for example processRequest with same signature as doGet or doPost and then call this method in both doGet and doPost method. see example below

public class HelloWorldServlet extends HttpServlet {
protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
PrintWriter out = response.getWriter();
out.println("Hello");
}


protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
processRequest(request,response);
}

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

}

Thanks a lot for you help... Resolved this issue... 

you welcome

Great work by SK(MS-SE) ..........

plz tell me how can i resolved this?

RSS

Latest Activity

Profile Iconrimsha pervaiz, Mumtaz Hussain and Saira Shahzad joined Virtual University of Pakistan
3 minutes ago
♦_"Tooba"_♦ liked +¢αяєℓєѕѕ gιяℓ's discussion xD.........................پرانی محبوبہ کے نام
16 minutes ago
+ M.Tariq Malik commented on ♦_"Tooba"_♦'s status
16 minutes ago
+¢αяєℓєѕѕ gιяℓ liked ♦_"Tooba"_♦'s discussion Guzri Howi Zindagi Ko Kabhi Yaad Na Kr
18 minutes ago
+¢αяєℓєѕѕ gιяℓ replied to ♦_"Tooba"_♦'s discussion Guzri Howi Zindagi Ko Kabhi Yaad Na Kr
19 minutes ago
♦_"Tooba"_♦ posted a status
"Shikwa ye zulmat sey tho kahan behtar tha Apne hisse ke koi shama jalate jate…"
21 minutes ago
+¢αяєℓєѕѕ gιяℓ liked + M.Tariq Malik's discussion Follow the Main Forum & Study Groups New Added Discussions at Your Mail Address
32 minutes ago
+¢αяєℓєѕѕ gιяℓ replied to + M.Tariq Malik's discussion Follow the Main Forum & Study Groups New Added Discussions at Your Mail Address
32 minutes ago
+¢αяєℓєѕѕ gιяℓ liked +¢αяєℓєѕѕ gιяℓ's discussion xD.........................پرانی محبوبہ کے نام
34 minutes ago
+¢αяєℓєѕѕ gιяℓ replied to +¢αяєℓєѕѕ gιяℓ's discussion xD.........................پرانی محبوبہ کے نام
34 minutes ago
+¢αяєℓєѕѕ gιяℓ replied to +¢αяєℓєѕѕ gιяℓ's discussion xD.........................پرانی محبوبہ کے نام
35 minutes ago
+¢αяєℓєѕѕ gιяℓ replied to +¢αяєℓєѕѕ gιяℓ's discussion Jin sey Mohabbat Ho.....
36 minutes ago
+¢αяєℓєѕѕ gιяℓ replied to +¢αяєℓєѕѕ gιяℓ's discussion Jin sey Mohabbat Ho.....
37 minutes ago
+¢αяєℓєѕѕ gιяℓ replied to +¢αяєℓєѕѕ gιяℓ's discussion Iss Mien Fail Karn wali Kon C baat thi xD
39 minutes ago
+¢αяєℓєѕѕ gιяℓ replied to +¢αяєℓєѕѕ gιяℓ's discussion Iss Mien Fail Karn wali Kon C baat thi xD
39 minutes ago
+¢αяєℓєѕѕ gιяℓ replied to +¢αяєℓєѕѕ gιяℓ's discussion Iss Mien Fail Karn wali Kon C baat thi xD
40 minutes ago
ϝ ι ყ α replied to +¢αяєℓєѕѕ gιяℓ's discussion Iss Mien Fail Karn wali Kon C baat thi xD
1 hour ago
ϝ ι ყ α replied to 彡JK彡 ❤️'s discussion Dedicated To All Fake IDs............ :p:p
1 hour ago
+!!!AAg❤️ replied to + "αяsαℓ " Ќąƶµяɨ •"'s discussion Muhabato me li gaye kasmain
1 hour ago
Rehman liked ♦_"Tooba"_♦'s discussion Guzri Howi Zindagi Ko Kabhi Yaad Na Kr
1 hour ago

© 2019   Created by + M.Tariq Malik.   Powered by

Promote Us  |  Report an Issue  |  Privacy Policy  |  Terms of Service