http://WebApp-url/servlet/package.Class 로 class 를 실행
/WEB-INF/classes 아래의 class 가 실행 됨.

1. WAS 설정
 

resin - resin.conf
<web-app id='/'>
  ..
  <servlet-mapping url-pattern='/servlet/*' servlet-name='invoker'/>
  ..
</web-app>

jeus - web.xml
<web-app>
  <servlet>
    <servlet-name>WorkerServlet</servlet-name>
    <servlet-class>jeus.servlet.servlets.WorkerServlet</servlet-class>
    <init-param>
      <param-name>ServletRoot</param-name>
      <param-value>/home/WEB-INF/classes/</param-value>
    </init-param>
 <init-param>
  <param-name>PackageSeparator</param-name>
 <param-value>.</param-value>
 </init-param>
    <load-on-startup>-1</load-on-startup>
  </servlet>
  <servlet-mapping>
    <servlet-name>WorkerServlet</servlet-name>
    <url-pattern>/servlet/*</url-pattern>
  </servlet-mapping>
</web-app>

weblogic - web.xml
<servlet>
  <servlet-name>ServletServlet</servlet-name>
  <servlet-class>weblogic.server.ServletServlet</servlet-class>
  <load-on-startup>-1</load-on-startup>
</servlet>

<server-mapping>
  <servlet-name>ServletServlet</servlet-name>
  <url-pattern>/servlet/*</url-pattern>
</servlet-mapping>

tomcat - web.xml

    <servlet>
        <servlet-name>default_servlet</servlet-name>
        <servlet-class>
          org.apache.catalina.servlets.InvokerServlet
        </servlet-class>
        <init-param>
            <param-name>debug</param-name>
            <param-value>0</param-value>
        </init-param>
        <load-on-startup>2</load-on-startup>
    </servlet>

    <servlet-mapping>
        <servlet-name>default_servlet</servlet-name>
        <url-pattern>/sevlet/*</url-pattern>
    </servlet-mapping>


2. Servlet Java 파일

package test;

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

import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

public class Test extends HttpServlet
{
    public void doGet(HttpServletRequest req, HttpServletResponse res) throws IOException
    {
        doService(req, res);
    }

    public void doPost(HttpServletRequest req, HttpServletResponse res) throws IOException
    {
        doService(req, res);
    }

    public void doService(HttpServletRequest req, HttpServletResponse res) throws IOException
    {
        req.setCharacterEncoding("euc-kr"); //euc-kr encoding
        HttpSession session = req.getSession();

        if(session == null){
            res.setContentType("text/html;charset=euc-kr"); //euc-kr encoding
            PrintWriter out = res.getWriter();
            out.print("로그인이 필요합니다.");
            out.print("alert 창으로띄운다.");
            out.close();
        }

        res.sendRedirect("/index.jsp");

        String test = req.getParameter("test");
        System.out.println("test="+test);
    }

}

3. jsp 파일

<%@ page contentType="text/html; charset=euc-kr" %>
<%@ page pageEncoding="euc-kr" %>
<meta http-equiv="content-type" content="text/html; charset=euc-kr" />

<form action='/servlet/test.Test'>
  <input type='text' id='test' value='안녕..'>
  <input type='submit'>
</form>

+ Recent posts