0

The app welcome page is running however when I'm clicking on hyperlink it shows an error:

Type Status: Report

Message: /Welcome/nextPage

Description: The origin server did not find a current representation for the target resource or is not willing

My guess it is something to do with the web.xml file. One of my attemps was to write the following:

<?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" version="3.1">
  <display-name>MyApp</display-name>
  <welcome-file-list>
    <welcome-file>WelcomeServlet</welcome-file>
  </welcome-file-list>
      <servlet>
        <servlet-name>NextPageServlent</servlet-name>
        <jsp-file>/NextPageServlent/nextPage.jsp</jsp-file>
    </servlet>

    <servlet-mapping>
        <servlet-name>NextPageServlent</servlet-name>
        <url-pattern>/NextPageServlent/*</url-pattern>
    </servlet-mapping>
</web-app>

However it doesn't help, I have the same problem

edit: hyperlink that leads to 'nextPage'

index.jsp:

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>


<%
    String table=(String) request.getAttribute("table");

%>



<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">

<title>table content</title>

</head>

<body>

<h1>table content</h1>

<p>
<a href="nextPage">go to the next page </a>
</p>

<%= table %>


</body>
</html>

the web page link: http://localhost:8080/Welcome/nextPage

Is there a way not to use web.xml file?

student
  • 37
  • 6

2 Answers2

0

Is "nextPage.jsp" is inside the folder "NextPageServlent" if not then just put

<jsp-file>/nextPage.jsp</jsp-file>

instead of

<jsp-file>/NextPageServlent/nextPage.jsp</jsp-file>

i hope it helps..

Spr k
  • 36
  • 6
0

created index.jsp in webcontent

Welcome <a href="next">next page</a>

In xml

<servlet>
    <servlet-name>NextPageServlent</servlet-name>
    <jsp-file>/NewFile.jsp</jsp-file>
</servlet>

<servlet-mapping>
    <servlet-name>NextPageServlent</servlet-name>
    <url-pattern>/next/*</url-pattern>
</servlet-mapping>

NewFile.jsp is also inside the webcontent

Works perfectly

Spr k
  • 36
  • 6
  • In index.jsp you have wrote... what does the 'Welcome' stands for? – student May 24 '18 at 06:32
  • its just a text nothing to do with the code you can write anything you want. Ignore the 'Welcome' – Spr k May 24 '18 at 06:35
  • i found the source of the problem. You have used the "NextPageServlent/*" in url pattern Why ? – Spr k May 24 '18 at 06:41
  • Thanks A LOT!!!!!! but why I get null instead of a table? (jsp file of a Welcome page and the one of the next page use similar code... actually that is why my welcome-file in xml is WelcomeServlet and not index.jsp (since index.jsp gave null instead of a table but WelcomeServlet shows the table, the WelcomeServle is java code )....How to make the next page run properly, what changes should be done in web.xml? ) – student May 24 '18 at 06:52
  • this is the link of your another problem. Right? https://stackoverflow.com/questions/50477922/cant-display-the-table-when-running-index-jsp – Spr k May 24 '18 at 07:00
  • Ok so in the index.jsp you are requesting the attribute "table" and the in the servlet you are inserting the value in the table attribute. so if you directly open the index.jsp you will get null because the value is not inserted yet. To insert the value you will need the middle man and the "WelcomeServlet" is the middle man. don't hesitate to ask again if have still some doubts.. – Spr k May 24 '18 at 07:11
  • and by the way use "/next" in the url pattern to know the use of '*' check this [link](https://stackoverflow.com/questions/4140448/difference-between-and-in-servlet-mapping-url-pattern) – Spr k May 24 '18 at 07:19