So I did something stupid and didnt back up my code for my servlet page I managed to recover some but anyway I was able to get this to run before but now after repeating the steps from memory it wont run the method (which works as I have tested it seperately in the class) Anyone have any ideas why this may be?
Asked
Active
Viewed 111 times
1
-
well... what errors do you get? And from where in your code? – Jan Feb 22 '16 at 14:42
-
4Hint : your IDE probably has a "local history" feature. – Arnaud Denoyelle Feb 22 '16 at 14:42
-
@Jan I'm not getting any errors I click on the button nothing happens it just loads the page back again. Before it loaded for a while because the method takes time to run. – user3043724 Feb 22 '16 at 14:45
-
1Then you might want to look at your HTML / JSP as well - and your servlet mapping of cause. – Jan Feb 22 '16 at 14:46
-
can you post the code that is calling this post method? – angryip Feb 22 '16 at 14:51
-
1Not related to the question but you **should not** declare mutable variables as fields in the servlet class. Instead, move these variables inside each method that uses them. – Luiggi Mendoza Feb 22 '16 at 14:52
-
@angryip I have added it – user3043724 Feb 22 '16 at 14:55
-
@user3043724 are you using an annotation for the WebServlet? Is it mapped to the same name as the action in the jsp page? – angryip Feb 22 '16 at 15:00
-
also, isn't the – angryip Feb 22 '16 at 15:04
-
@angryip you genius yes i needed this line i completely forgot about it "${pageContext.request.contextPath}/myservlet" – user3043724 Feb 22 '16 at 15:14
-
as @angryip says, you need to configure that servlet either in web.xml or using annotation, then set the mapping-name in the action attribute of the – Yazan Feb 22 '16 at 15:14
-
How do you know it does not run? There are no log statements? Also can you include your web.xml and the rest of this class's implementation... speicfically any annotations on at the class level. – Jose Martinez Feb 22 '16 at 16:33
1 Answers
2
First Potential fix is to set the correct action:
<form action="${pageContext.request.contextPath}/index" method="POST" enctype="multipart/form-data" name="uploadForm">
<label for="file">Choose a file:</label>
<input type="file" name="file" width="150"/>
<input type="submit" value="Submit" name="submit"/>
<input type="submit" value="Tokenization" name="button1" />
<input type="submit" value="Split" name="button2" />
<input type="submit" value="pos" name="button3" />
</form>
This is inferring that your Servlet has the following URL path:
@WebServlet(urlPatterns = {"/index"})
public class Index extends HttpServlet {

user3043724
- 51
- 1
- 6

angryip
- 2,140
- 5
- 33
- 67
-
I was actually missing this ${pageContext.request.contextPath}/myServlet this should be added as the action – user3043724 Feb 22 '16 at 15:19
-
@user3043724 cool! just update the provided answer with your solution. Just include the mapping for the Servlet, so that it is easier for others to know if they get stuck in a similar area – angryip Feb 22 '16 at 15:23
-