Marco Fung

Greenhorn
+ Follow
since Jul 25, 2005
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
In last 30 days
0
Forums and Threads

Recent posts by Marco Fung

I tried it, it works.

But I had a mock question in j2eecertificate, it said it's not work.
19 years ago
JSP
Assume the name, attribute of a bean is correctly set.

So that
<jsp:getProperty name="id" property="firstName"/>
is valid.

Is

<jsp:getProperty name="id" property="firstName"></jsp:getProperty>

also valid? Does </jsp:getProperty> tag exists?
19 years ago
JSP
Try change your JSP to

<form method ="GET" action = "/TestResult.do">

<center><input type="submit"></center>
</form>

If I am right, since JSP will translate and compile into servlet. When a relative path is used, the generate JSP_servlet will use it related path to find another servlet.

In the cases, the relative path included the directory of the jsp, which doesn't fall into the context path.
This is the servlet code:

package com.example.web;

import com.example.model.*;
import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
import java.util.*;

public class BeerSelect extends HttpServlet{

public void doPost(HttpServletRequest req, HttpServletResponse res)
throws IOException, ServletException{

res.setContentType("text/html");
PrintWriter out = res.getWriter();

out.println("Beer Selection Advice<br>");
String c = req.getParameter("COLOR");

BeerExpert be = new BeerExpert();
List result = be.getBrands(c);

req.setAttribute("styles", result);

RequestDispatcher view = req.getRequestDispatcher("result.jsp");
view.forward(req, res);

}
}

And this is my DD:

<web-app xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsl="http://www.w3.org/2001/XMLSchema-instance"
xsl:schemaLocation="http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"
version="2.4">

<security-constraint>
<web-resource-collection>
<url-pattern>/SelectBeer.do</url-pattern>
<http-method>POST</http-method>
</web-resource-collection>
<auth-constraint>
<role-name>member</role-name>
<role-name>admin</role-name>
</auth-constraint>
</security-constraint>

<security-role>
<role-name>member</role-name>
<role-name>guest</role-name>
</security-role>

<login-config>
<auth-method>FORM</auth-method>
<form-login-config>
<form-login-page>/loginPage.html</form-login-page>
<form-error-page>/loginError.html</form-error-page>
</form-login-config>
</login-config>

<error-page>
<exception-type>java.lang.Throwable</exception-type>
<location>/errorPage.jsp</location>
</error-page>

<servlet>
<servlet-name>Ch3 Beer</servlet-name>
<servlet-class>com.example.web.BeerSelect</servlet-class>
</servlet>

<servlet-mapping>
<servlet-name>Ch3 Beer</servlet-name>
<url-pattern>/SelectBeer.do</url-pattern>
</servlet-mapping>

<context-param>
<param-name>mainEmail</param-name>
<param-value>[email protected]</param-value>
</context-param>
</web-app>

And this is my loginPage.html:

<html><body>
Please login:

<form method="POST" action="j_security_check">
<input type="text" name="j_username">
<input type="password" name="j_password">
<input type="submit" value="Enter">
</form>

</body></html>
Hi, I have a problem when using a FORM authentication method in my web app.

my DD is as follow:

<login-config>
<auth-method>FORM</auth-method>
<form-login-config>
<form-login-page>/loginPage.html</form-login-page>
<form-error-page>/loginError.html</form-error-page>
</form-login-config>
</login-config>

I have no problem to trigger the loginPage.html, when I try to accessed a authentication required servlet that uses a doPost() method without doGet().

When I typed in a invalid username/password pair, it go to loginError.html page.

However, when I typed in a valid username/password pair, I will be forward to a error page

--> HTTP 405 : HTTP method GET is not supported by this URL

But when i use the same browser and try to access the same servlet again, it went through with no problem and generate the expected output.

Can anyone please tell me what happen? I use Tomcat 5.0.28
In your tomcat setting, you use Admin.

but in your web.xml, you use a different name, Adm.
In your Tld file, have you try to define the movieList rtexprvale to true?

<attribute>
<name>movieList</name>
<required>true</required>
<rtexprvalue>true</rtexprvalue>
</attribute>
19 years ago
JSP