question

JumboDumbo-8428 avatar image
1 Vote"
JumboDumbo-8428 asked JackJJun-MSFT commented

how to create a Servlet in a c# client

So I am trying to make a Servlet in my c# programm related to my h2 database and I cant figure out how to create a c# Servlet, or Client?

This is my Servlet(implemented in Java):

@WebServlet(name = "helloServlet", value = "/hello-servlet")
public class HelloServlet extends HttpServlet {


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

     Employee employee = JSP_Client.getEmployee(request.getParameter("name"));
     System.out.println(employee);
     request.setAttribute("selectedEmployee", employee);
     RequestDispatcher requestDispatcher = request.getRequestDispatcher("employee.jsp");
     requestDispatcher.forward(request,response);
 }
 public void destroy() {
 }

}

And my Client looks like this:

package Controller;

import common.IEmployee;
import common.ILogBookEntry;
import model.Employee;
import org.eclipse.microprofile.rest.client.RestClientBuilder;

import java.net.URI;
import java.util.ArrayList;

public class Client {
public static IEmployee employees;
public static ILogBookEntry entries;

 public Client() {
 }

 public static void employeeClient() {
     employees = RestClientBuilder.newBuilder()
             .baseUri(URI.create("http://localhost:8080/LERN-1.0-SNAPSHOT/api"))
             .followRedirects(true)
             .build(IEmployee.class);
 }
 public static void logbookEntryClient() {
     entries = RestClientBuilder.newBuilder()
             .baseUri(URI.create("http://localhost:8080/LERN-1.0-SNAPSHOT/api"))
                     .followRedirects(true)
                     .build(ILogBookEntry.class);
 }

 public static ArrayList<Employee> getAllEmployees(){
     employeeClient();
     return (ArrayList<Employee>) employees.getAllEmployees();
 }

 public static Employee getEmployee(String name){
     for (Employee emp:getAllEmployees()) {
         if(emp.getFirstName().equals(name)){
             return emp;
         }
     }
     return null;
 }

}

Can someone help me implement a c# client, as I am quite new to c# and dotNet

dotnet-csharp
· 2
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

@JumboDumbo-8428, Welcome to Microsoft Q&A, it seems that you want to convert web java app to web c# app, right? If so, which type you want to use in c#, is asp.net app or asp.net core app? It will be better for me to analyze your problem to determine your project type.

0 Votes 0 ·

0 Answers