1

I have to ask you because i'm stuck and can't go on. I'm trying to make response path like this:

DAO-> Servlet-> JSP

The process is: user fills the form on jsp, clicks "Submit" and gets response on the same JSP (user added or didn't)

adding data to DB is working fine but i got error from WebBrowser :

Type Exception Report

Message can't parse argument number: pageContext.request.contextPath

Description The server encountered an unexpected condition that prevented it from fulfilling the request.

here is my jsp code:

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib prefix ="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix ="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
<%@ taglib prefix ="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>

<%@ page isELIgnored="false"%>
<script type="text/javascript" src="${pageContext.request.contextPath}/jQuery.js"/></script>

<!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=UTF-8">
<title>dodaj pracownika</title>
</head>
<body>
<f:view>

<section id = registration" class = "section">
<div class "container tagline">
<em>{0}</em>


</div>
<br>

<AdContentProvider
Name="MIME-type"
Provider="addUser.class"
Properties="optional-properties-for-your-class"
>
</AdContentProvider>

<form action="${pageContext.request.contextPath}/newuser" method = "post">

<form>
<label> Imie</label> <input type="text" name= "imie" id="imie"> <br/>
<label> Nazwisko</label> <input type="text" name= "nazwisko" id="nazwisko"> <br/>
<label> Stanowisko</label> <input type="text" name= "stanowisko" id="stanowisko"> <br/>
<label> Stawka</label> <input type="text" name= "stawka" id="stawka"> <br/>

<input type ="submit" value="Dodaj" id = "dodaj">

</form>







</f:view>
</body>
</html>

and servlet code:

package tk.jewsbar.servlets;

import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.text.MessageFormat;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.transaction.Transactional;

import fasolki.Pracownik;
import tk.jewsbar.dao.Dao;



@WebServlet("/newuser")
public class addUser extends HttpServlet 
{

@Override
@Transactional
protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException
{


    String imie = req.getParameter("imie");
    String nazwisko = req.getParameter("nazwisko");
    String stanowisko = req.getParameter("stanowisko");
    double stawka = Double.valueOf(req.getParameter("stawka"));




    Pracownik pracownik = new Pracownik (imie,  nazwisko,  stanowisko, stawka);
    Dao dao = new Dao();


    int rows = dao.dodajUzytkownika(pracownik);







    String err = "null";


if (rows ==0)
{
    err = "Niestety nie udalo sie dodac uzytkownika";
}

else {

    err = "Dodano uzytkownika" + rows;
}

String pejcz = getHTMLString(req.getServletContext().getRealPath("html/newuser.jsp"), err);
resp.getWriter().write(pejcz);


}

public String getHTMLString(String sciezka, String message) throws IOException
{

    BufferedReader czytaj = new BufferedReader (new FileReader(sciezka));

    String linia = "";

    StringBuffer bufor = new StringBuffer();

    while((linia=czytaj.readLine())!= null)

            {
        bufor.append(linia);

            }

    czytaj.close();

        String pejcz = bufor.toString();

        pejcz = MessageFormat.format(pejcz,  message);


        return pejcz;

            }




    @Override
        protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

            String pejcz = getHTMLString(req.getServletContext().getRealPath("html/newuser.jsp"),"");
            resp.getWriter().write(pejcz);
        }

}
Klose
  • 33
  • 1
  • 1
  • 6
  • i've changed it and now i have error like this: Type Exception Report Message can't parse argument number: contextPath Description The server encountered an unexpected condition that prevented it from >fulfilling the request. – Klose Sep 05 '18 at 12:41

1 Answers1

0

try like this

<script type="text/javascript"  src="<c:out value="${contextPath}"/>/jQuery.js"></script>

or

<script type="text/javascript"  src="<c:out value="${pageContext.request.contextPath}"/>/jQuery.js"></script>

Instead of

<script type="text/javascript" src="${contextPath}/jQuery.js"/></script>

You may read the suggestions on this link , expression-language-in-jsp-not-working

user595226
  • 89
  • 3
  • 10