0

While I'm Running my index.html file I'm getting a Error Which looks like this[enter image description here][1]

And after checking all the files(web.xml,index.html and the java servlet)file I found this

[enter image description here][2]

Which says

"The package javax.servlet.http is accessible from more than one module: servlet.api, tomcat.i18n.es, tomcat.i18n.fr, tomcat.i18n.ja"

What to do?

package com.kmit.sonet;
import java.util.Arrays;

import java.io.IOException; 
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.ServletOutpuxtStream;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

//Extend HttpServlet class
public class Capital extends HttpServlet {

 private static final long serialVersionUID = 1L;

 public Capital() {
 }

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

  // Set response content type
  response.setContentType("text/html");

  PrintWriter out = response.getWriter();
  String title = "Select a state";
  String responseString = "empty";
    String  Capof = request.getParameter("state");

  

  out.println("<html>");
  out.println("<head><title>" + title + "</title></head>");

  out.println("<body>");
  out.println(" <b>" + Capof + " is " + responseString  + "</b>");
  out.println("</body>");
  out.println("<html>");
  
  if(Capof=="Andhra Pradesh")
  {
     responseString="Hyderabad";
    
  }
    

 }

 // function to give out the capital as output
 
 
 
}
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://xmlns.jcp.org/xml/ns/javaee" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd" id="WebApp_ID" version="3.1">
  <display-name>PrimeChecker</display-name>
  
    <!-- Define servlet, named primeNumber -->
<servlet>
   <servlet-name>City</servlet-name>
   <servlet-class>com.kmit.sonet.Capital</servlet-class>
</servlet>
 
<!-- Defines the path to a2ccess this Servlet -->
<servlet-mapping>
   <servlet-name>City</servlet-name>
   <url-pattern>/Capital</url-pattern>
</servlet-mapping>
  
  
  <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>
</web-app>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
<select id="State" name="Capof">
<option value="Andhra Pradesh" >Andhra Pradesh</option>
<option value="Arunachal Pradesh">Arunachal Pradesh</option>
<option value="Assam">Assam</option>
<option value="Bihar">Bihar</option>
<option value="Chandigarh">Chandigarh</option>
<option value="Chattisgarh">Chattisgarh</option>
<option value="Goa">Goa</option>
<option value="Gujarat">Gujarat</option>
<option value="Hryana">Haryana</option>
<option value="Himachal Pradesh">Himachal Pradesh</option>
<option value="Jammu and Kashmir">Jammu and Kashmir</option>
<option value="Jharkhand">Jharkhand</option>
<option value="Karnataka">Karnataka</option>
<option value="Kerala">Kerala</option>
<option value="Madhya Pradesh">Madhya Pradesh</option>
<option value="Maharashtra">Maharashtra</option>
<option value="Manipiur">Manipur</option>
<option value="Meghalaya">Meghalaya</option>
<option value="Mizoram">Mizoram</option>
<option value="Odisha">Odisha</option>
<option value="Punjab">Punjab</option>
<option value="Rajasthan">Rajasthan</option>
<option value="Sikkim">Sikkim</option>
<option value="Tamil Nadu">Tamil Nadu</option>
<option value="Telangana">Telangana</option>
<option value="Tripura">Tripura</option>
<option value="Uttar Pradesh">Uttar Pradesh</option>
<option value="Uttarakhand">Uttarakhand</option>
<option value="West Bengal">West Bengal</option>

 



</select>

<input type="submit" value="Submit" />

</body>
</html>
A S K VYAS
  • 3
  • 1
  • 6
  • Btw my Os is Mac high Sierra – A S K VYAS Aug 02 '18 at 14:33
  • 1
    maybe this can come in handy https://stackoverflow.com/questions/46834695/the-package-org-openqa-selenium-is-accessible-from-more-than-one-module – catchiecop Aug 02 '18 at 14:42
  • I did it I'm still getting the HTTP Status-404 But the errors in the servlet are gone – A S K VYAS Aug 02 '18 at 14:53
  • there is probably an error on the web.xml as the servlet seems to work fine since you get the 404 error. Check if you have the servlet mapping correct in your application's web.xml. – catchiecop Aug 02 '18 at 14:56
  • Checked It but still giving the same message I also edited all the file names and the packages accordingly still getting the same message – A S K VYAS Aug 03 '18 at 06:30
  • Can someone please post the code of mapping an input html select tags to java servlet through xml to get an output on a tomcat server I'm trying it since 4 days I do not understand how it works using a hashmap – A S K VYAS Aug 03 '18 at 07:11
  • I still think the error must be in the web.xml so could you please update your question and add it there so I can look it up ? – catchiecop Aug 03 '18 at 07:16
  • I meant you adding the web.xml not the index.html file :P – catchiecop Aug 03 '18 at 10:36
  • Sorry bro I tried to add all the files but got some error kind of thing I'm still a noob I'll update the screenshots asap – A S K VYAS Aug 03 '18 at 15:22
  • Just copy paste the code of the xml you don't need to upload screenshots for everything. There is a code format option so you just need to select that and paste your code in it – catchiecop Aug 03 '18 at 15:24
  • Edited the code – A S K VYAS Aug 06 '18 at 03:48

2 Answers2

0

this error is coming due to servlet jar is added by multiple source. If you added servlet jar from web server kindly check build path either multiple version of web server will be at build path

-1

Solution

Right----"Properties----> Java build Path----> Libraries----> ClassPath---->add Library----> Server R Untime----> Next----> select tomcat----> Finish